DataGrid里执行删除功能,而我的数据在数据库里是联合主键,下面是我编的删除功能的,我点击了删除后,它既不报错也不反映,到底错在哪里?
private void Dgd_contract1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlConnection con=new SqlConnection("server=260915-F611EC1C;uid=sa;pwd=sa;DATABASE=Purchase_Management");
con.Open();
string strsql="delete from contract_detail where contract_id=@contract_id and product_id=@product_id";
SqlCommand cmd =new SqlCommand (strsql,con);
cmd.Parameters.Add ("@product_id",SqlDbType.VarChar,20);
cmd.Parameters .Add ("@contract_id",SqlDbType.VarChar,20);

string KeyID_1=e.Item.Cells[1].Text.ToString();
cmd.Parameters["@product_id"].Value =KeyID_1; string KeyID_2=e.Item.Cells[0].Text.ToString();
cmd.Parameters["@contract_id"].Value =KeyID_2;
cmd.ExecuteNonQuery();
}

解决方案 »

  1.   

    SqlConnection con=new SqlConnection("server=260915-F611EC1C;uid=sa;pwd=sa;DATABASE=Purchase_Management"); 
    string strsql="delete from contract_detail where contract_id=@contract_id and product_id=@product_id"; 
    SqlCommand cmd =new SqlCommand (strsql,con); 
    cmd.Parameters.Add ("@product_id",SqlDbType.VarChar,20); 
    cmd.Parameters .Add ("@contract_id",SqlDbType.VarChar,20); string KeyID_1=e.Item.Cells[1].Text; //单步调试看看这里值是否正确
    cmd.Parameters["@product_id"].Value =KeyID_1; string KeyID_2=e.Item.Cells[0].Text; //单步调试看看这里值是否正确
    cmd.Parameters["@contract_id"].Value =KeyID_2; 
    con.Open(); 
    cmd.ExecuteNonQuery(); 
    con.Close();
    //重新绑定数据
      

  2.   

    并且要第一次时加个,!ISPOSTBACK
      

  3.   

    把值传进去,
    delete 语句在数据库中试行一下试一下。值对的话,应该是可以删除的