当前位置: 代码迷 >> ASP.NET >> 大家帮帮忙,看看有关问题出在那里!
  详细解决方案

大家帮帮忙,看看有关问题出在那里!

热度:4935   发布时间:2013-02-26 00:00:00.0
大家帮帮忙,看看问题出在那里!!
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();
}
用这种方法试试,肯定行
  相关解决方案