首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-02-05 
大家帮帮忙,看看问题出在那里!!ProtectedSubGridView1_RowDeleting(ByValsenderAsObject,ByValeAsSystem.W

大家帮帮忙,看看问题出在那里!!
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();
}
用这种方法试试,肯定行

热点排行