-2
請幫助我解決錯誤「索引超出範圍。非負數且小於集合的大小參數名:。指標。由此是我的代碼謝謝如何解決「錯誤:索引超出範圍,必須是非負數,小於集合的大小參數名稱:索引」
Dim index As Integer
Dim index1 As Integer
index1 = e.RowIndex + 1
//the error was here
index = GridView1.DataKeys(index1).Values(0)
index = Convert.ToInt32(index)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New MySqlConnection(constr)
Using cmd As New MySqlCommand("DELETE from tblauditplan WHERE AuditArea = @auditarea")
Using sda As New MySqlDataAdapter()
cmd.Parameters.AddWithValue("@auditplan", index)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Using
Me.BindGrid()
End Sub
使用調試器,並找出它。 –
你的代碼沒有檢查'index1 = e.RowIndex + 1'之前是否有足夠的行' – Plutonix
謝謝你的評論Plutonix和T McKeown。我會嘗試你的建議/評論。 –