当前位置:编程学习 > C#/ASP.NET >>

GridView中删除某行

--------------------编程问答-------------------- string sqlstr = "delete from [reg_stu] where [stu_id]=" + stu_id;

stu_id里面有值没有? --------------------编程问答--------------------
protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int stu_id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value.ToString());//你获取的行ID是GridView中的行索引,和数据库同步的? 
  string sqlstr = "delete from [reg_stu] where [stu_id]=" + stu_id;

        SqlConnection con = new SqlConnection(sqlstr);
        con.Open();
        SqlCommand cmd = new SqlCommand(sqlstr,con);
        cmd.ExecuteNonQuery();
        cmd.Dispose();
        con.Close();
        GridView2.EditIndex =- 1;
        this.bind();
 
    }
--------------------编程问答-------------------- 可以看看   GridView 72 绝技. --------------------编程问答-------------------- 跟跟断点,看看最终生成的语句
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,