//执行删除数据操作
SqlConnection con=new SqlConnection(连接字符串);
DataRow r=dsCus1.Tables[0].Rows[dataGrid1.CurrentRowIndex];
if(MessageBox.Show("是否要删除"+r[0].ToString()+"号客户?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="delete from power_customer where
PONO=@id";
SqlParameter para=cmd.Parameters.Add("@id",SqlDbType.Char,30);
para.Value=r[0].ToString();
sqlDataAdapter1.DeleteCommand=cmd;
r.Delete();
try
{
sqlDataAdapter1.Update(dsCus1.Tables[0].Select("","",DataViewRowState.Deleted));
}
catch(SqlException er)
{
MessageBox.Show(er.Message);
dsCus1.Tables[0].RejectChanges();
return;
}
MessageBox.Show("已成功删除信息");
}
这个需要向导建立sqlDataAdapter1 以及数据集dsCus