指定的参数已超出有效值的范围。参数名: index?
在显示students数据表的DataGrid控件中对数据进行编辑(totalscore)操作。数据库用
Access.EditStudent,CancelEdit代码都正确,Run时,UpdateStudent报错,代码如下:
Sub UpdateStudent(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim TotalScore As TextBox
TotalScore = e.Item.Cells(3).Controls(0) <--指定的参数已超出有效值的范围。参数
名: index
Dim strSQL As String
strSQL = "Update students Set totalscore=@totalscore Where studentid=@studentid"
Dim cmd As New System.Data.OleDb.OleDbCommand(strSQL, conn)
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@totscore",
System.Data.OleDb.OleDbType.Decimal, Nothing))
cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@studentid",
System.Data.OleDb.OleDbType.VarChar, 8))
cmd.Parameters("@totscore").Value = CType(TotalScore.Text, Decimal)
cmd.Parameters("@studentid").Value = DataGrid1.DataKeys.Item(e.Item.ItemIndex)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub