怎样删除数据库一行信息通过C#实现
展开全部
以下例子, 在表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();
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();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询