代码: Dim strid, strsql As String
strid = dg.DataKeys.Item(e.Item.ItemIndex)
strsql = "delete from student where studentid='" & strid & "'"
Dim sqlcon As New SqlClient.SqlConnection("server=zhao2310;database=zhao;user id=sa;password=")
sqlcon.Open()
Dim sqlcommand As New SqlClient.SqlCommand
sqlcommand.Connection = sqlcon
sqlcommand.CommandText = strsql
sqlcommand.ExecuteNonQuery()
sqlcon.Close()
sqlcon = Nothing
dg.EditItemIndex = -1
bindgrid()
错误:
异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。参数名: index
strid = dg.DataKeys.Item(e.Item.ItemIndex)提示该行有问题!!!
strid = dg.DataKeys.Item(e.Item.ItemIndex)
strsql = "delete from student where studentid='" & strid & "'"
Dim sqlcon As New SqlClient.SqlConnection("server=zhao2310;database=zhao;user id=sa;password=")
sqlcon.Open()
Dim sqlcommand As New SqlClient.SqlCommand
sqlcommand.Connection = sqlcon
sqlcommand.CommandText = strsql
sqlcommand.ExecuteNonQuery()
sqlcon.Close()
sqlcon = Nothing
dg.EditItemIndex = -1
bindgrid()
错误:
异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。参数名: index
strid = dg.DataKeys.Item(e.Item.ItemIndex)提示该行有问题!!!
strid = dg.DataKeys(e.Item.ItemIndex)
2.你上述的代码,是放在什么事件里面?
3.你可把你的e.Item.ItemIndex打印出来,看看它到底是什么值.