System.ArgumentOutOfRangeException

L

leezard

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.CommandBehavior.CloseConnection)
MyDataGrid.DataSource = objDR
MyDataGrid.DataBind()
conn.close
End Sub

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top