Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > System.ArgumentOutOfRangeException

Reply
Thread Tools

System.ArgumentOutOfRangeException

 
 
leezard
Guest
Posts: n/a
 
      08-20-2003
Specified argument was out of the range of valid values. Parameter name:
index
Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index
Below is my code:

Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
MyDataGrid.EditItemIndex = e.Item.ItemIndex
BindData
End Sub
Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
BindData()
End Sub

Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
Dim conn As SqlConnection
Dim MyCommand As SqlCommand
Dim strConn as string =
"server=localhost;trusted_connection=true;database =PTG"
Dim txtDate As textbox = E.Item.cells(2).Controls(0)
Dim txtMorning As textbox = E.Item.cells(3).Controls(0)
Dim txtAfternoon As textbox = E.Item.cells(4).Controls(0)
Dim txtNight As textbox = E.Item.cells(5).Controls(0)
Dim txtMin As textbox = E.Item.cells(6).Controls(0)
Dim txtMax As textbox = E.Item.cells(7).Controls(0)
Dim strUpdateStmt As String

strUpdateStmt =" UPDATE Weather SET" & _
" Date =@Date, morning =@morning, afternoon =@afternoon, night
=@night, min =@min, max =@max" & _
" WHERE wea_id = @wea_id "
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New SQLParameter("@Date", txtDate.text))
MyCommand.Parameters.Add(New SQLParameter("@morning",
txtMorning.text))
MyCommand.Parameters.Add(New SQLParameter("@afternoon",
txtAfternoon.text))
MyCommand.Parameters.Add(New SQLParameter("@night", txtNight.text))
MyCommand.Parameters.Add(New SQLParameter("@min", txtMin.text))
MyCommand.Parameters.Add(New SQLParameter("@max", txtMax.text))
MyCommand.Parameters.Add(New SQLParameter("@wea_id",
e.Item.Cells(1).Text ))
conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData
End Sub

Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
BindData
end if
End Sub
Sub BindData()
Dim strConn as string =
"server=localhost;trusted_connection=true;database =PTG"
Dim sql as string = "Select wea_id, Date, morning, afternoon, night, min,
max from Weather"
Dim conn as New SQLConnection(strConn)
Dim objDR as SQLDataReader
Dim Cmd as New SQLCommand(sql, conn)
conn.Open()
objDR=Cmd.ExecuteReader(system.data.CommandBehavio r.CloseConnection)
MyDataGrid.DataSource = objDR
MyDataGrid.DataBind()
conn.close
End Sub

Thanks in advance.


 
Reply With Quote
 
 
 
 
leezard
Guest
Posts: n/a
 
      08-20-2003
I've figured it out.
thanks for viewing.

"leezard" <(E-Mail Removed)> wrote in message
news:ODEgu%(E-Mail Removed)...
> Specified argument was out of the range of valid values. Parameter name:
> index
> Exception Details: System.ArgumentOutOfRangeException: Specified argument
> was out of the range of valid values. Parameter name: index
> Below is my code:
>
> Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
> MyDataGrid.EditItemIndex = e.Item.ItemIndex
> BindData
> End Sub
> Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
> MyDataGrid.EditItemIndex = -1
> BindData()
> End Sub
>
> Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
> Dim conn As SqlConnection
> Dim MyCommand As SqlCommand
> Dim strConn as string =
> "server=localhost;trusted_connection=true;database =PTG"
> Dim txtDate As textbox = E.Item.cells(2).Controls(0)
> Dim txtMorning As textbox = E.Item.cells(3).Controls(0)
> Dim txtAfternoon As textbox = E.Item.cells(4).Controls(0)
> Dim txtNight As textbox = E.Item.cells(5).Controls(0)
> Dim txtMin As textbox = E.Item.cells(6).Controls(0)
> Dim txtMax As textbox = E.Item.cells(7).Controls(0)
> Dim strUpdateStmt As String
>
> strUpdateStmt =" UPDATE Weather SET" & _
> " Date =@Date, morning =@morning, afternoon =@afternoon, night
> =@night, min =@min, max =@max" & _
> " WHERE wea_id = @wea_id "
> conn = New SqlConnection(strConn)
> MyCommand = New SqlCommand(strUpdateStmt, conn)
> MyCommand.Parameters.Add(New SQLParameter("@Date", txtDate.text))
> MyCommand.Parameters.Add(New SQLParameter("@morning",
> txtMorning.text))
> MyCommand.Parameters.Add(New SQLParameter("@afternoon",
> txtAfternoon.text))
> MyCommand.Parameters.Add(New SQLParameter("@night",

txtNight.text))
> MyCommand.Parameters.Add(New SQLParameter("@min", txtMin.text))
> MyCommand.Parameters.Add(New SQLParameter("@max", txtMax.text))
> MyCommand.Parameters.Add(New SQLParameter("@wea_id",
> e.Item.Cells(1).Text ))
> conn.Open()
> MyCommand.ExecuteNonQuery()
> MyDataGrid.EditItemIndex = -1
> conn.close
> BindData
> End Sub
>
> Sub Page_Load(Source as Object, E as EventArgs)
> if not Page.IsPostBack then
> BindData
> end if
> End Sub
> Sub BindData()
> Dim strConn as string =
> "server=localhost;trusted_connection=true;database =PTG"
> Dim sql as string = "Select wea_id, Date, morning, afternoon, night, min,
> max from Weather"
> Dim conn as New SQLConnection(strConn)
> Dim objDR as SQLDataReader
> Dim Cmd as New SQLCommand(sql, conn)
> conn.Open()
> objDR=Cmd.ExecuteReader(system.data.CommandBehavio r.CloseConnection)
> MyDataGrid.DataSource = objDR
> MyDataGrid.DataBind()
> conn.close
> End Sub
>
> Thanks in advance.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments