感谢论坛上老大为我解答,环境sql2005+vsweb2005  
  
protected void Page_Load(object sender, EventArgs e)
    {//显示数据
      SqlConnection mycon = new SqlConnection();
     mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
         mycon.Open();
         SqlCommand mycmd = new SqlCommand("select * FROM Table2",mycon);
         SqlDataReader sdr = mycmd.ExecuteReader();
         lb1.DataSource = sdr;
         lb1.DataTextField = "user_id";
         lb1.DataValueField = "user_id";
         lb1.DataBind();
         
 }
    protected void Button1_Click(object sender, EventArgs e)
    { //  删除数据        SqlConnection mycon = new SqlConnection();
        mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
        mycon.Open();
       SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
       } 为什么安了删除键还删不掉呢,

解决方案 »

  1.   

    这就是全部代码?你看看自己的的SqlCommand是不是没执行……
      

  2.   

    至少要ExcuteNoneQuery()才会有效吧。
      

  3.   

    SQL语句没有被执行吧!
    SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
    mycmd.ExecuteNonQuery();  //这句后面加上这句试试
      

  4.   

    没执行 
    加上mycmd.ExcuteNoneQuery();
      

  5.   

     mycmd.ExecuteNonQuery();加了这个还是不行艾
      

  6.   

      protected void Button1_Click(object sender, EventArgs e)
      { // 删除数据  SqlConnection mycon = new SqlConnection();
      mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
      mycon.Open();
      SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
      } 为什么安了删除键还删不掉呢,
    -------------------你创建了Command,但是没有执行啊
    mycmd.ExecuteNonQuery();
      

  7.   

    删除数据后,重新绑定数据。
    mycmd.ExecuteNonQuery();
    然后:
    SqlCommand mycmd = new SqlCommand("select * FROM Table2",mycon);
      SqlDataReader sdr = mycmd.ExecuteReader();
      lb1.DataSource = sdr;
      lb1.DataTextField = "user_id";
      lb1.DataValueField = "user_id";
      lb1.DataBind();
      

  8.   

    删除后 不是重新执行一次pagelode,??