以下例子, 在表Gl_account_code 中删除指定 Account_id值的记录,供参考:
private SqlConnection sqlconn = new SqlConnection("连接字符串");
string sqlstr = "Delete from Gl_account_code WHERE Account_id =@Account_id";
SqlCommand sqlcmd = new SqlCommand(sqlstr, sqlconn);
// 以下加入参数值
sqlcmd.Parameters.Add(new SqlParameter("@Account_id", SqlDbType.Int, 15));
sqlcmd.Parameters["@Account_id"].Value = 123; //分配参数值
try
{
sqlcmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show("Delete Error:" + ex.Message.ToString());
sqlcmd.Dispose();
return;
}
sqlcmd.Dispose();
delete from [表名] where [条件]