怎样删除数据库一行信息通过C#实现

2024-12-21 19:17:49
推荐回答(2个)
回答1:

以下例子, 在表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();

回答2:

delete from [表名] where [条件]