Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim id As String = GridView1.DataKeys(e.RowIndex).Values(0).ToString() 这一句提示错误,"索引超出范围。必须为非负值并小于集合大小。参数名: index"
Dim conn As String = System.Configuration.ConfigurationManager.ConnectionStrings( "mycon ").ToString()
Dim myconnection As SqlConnection = New SqlConnection(conn)
myconnection.Open()
Dim mycommand As SqlCommand = New SqlCommand( "delete from grouptable where groupid= " & id, myconnection)
mycommand.ExecuteNonQuery()
myconnection.Close()
GridView1.DataBind()
End Sub
------解决方案--------------------------------------------------------
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string userID = this.GridView1.DataKeys[e.RowIndex].ToString();
OleDbConnection con = new OleDbConnection( "provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/web/mdb/data.mdb ");
con.Open();
OleDbCommand cmd = new OleDbCommand( "delete from login where userID= ' " + userID + " ' ", con);
cmd.ExecuteNonQuery();
this.GridViewToBind();
}
用这种方法试试,肯定行