using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=物流数据库;Integrated Security=True"))
                {
                    
                     conn.Open();
                     SqlCommand cmd = new SqlCommand("Delete from T_CheLiang where id=id", conn);
                     cmd.ExecuteNonQuery();
                     conn.Close();
                     this.Close();                }上面这样写  直接把 表里的资料都删掉我想按行删除  
id=@id   报错啊! 

解决方案 »

  1.   

     SqlCommand cmd = new SqlCommand("Delete from T_CheLiang where id="+id, conn);
     
      

  2.   

    int id=1;
    SqlCommand cmd = new SqlCommand("Delete from T_CheLiang where id="+id, conn);
      

  3.   

    或用存储过程传参数
    SqlCommand cmd = new SqlCommand("Delete from T_CheLiang where id=@id", conn);
      

  4.   

    id  能不能是在 dataGridView1 里 点击赋值的啊?
      

  5.   

    string sql = string.Format("delete from Account where AID = '{0}'", dataGridView1.SelectedRows[0].Cells[0].Value);要是还不会的可以去我博客看,我写了两个控件的增删改查。一个listView,一个DataGridView.
      

  6.   

      using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=物流数据库;Integrated Security=True"))
                    {
           int id=0;             
                         conn.Open();
                         SqlCommand cmd = new SqlCommand("Delete from T_CheLiang where id="+id, conn);
                         cmd.ExecuteNonQuery();
                         conn.Close();
                         this.Close();                }