ASP.Net简单更新方法举例
程序员文章站
2022-04-12 22:01:11
public int Update()
{
string sql = "update student set xingming=@xingming wher...
public int Update()
{
string sql = "update student set xingming=@xingming where xuehao=@xuehao";
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
SqlCommand command = new SqlCommand(sql,conn);
SqlParameter parm = new SqlParameter("@xuehao","001");
command.Parameters.Add(parm);
parm = new SqlParameter("@xingming", "张三");
command.Parameters.Add(parm);
try
{
conn.Open();
return command.ExecuteNonQuery();
}
catch (SqlException ex)
{
return -1;
}
finally
{
conn.Close();
}
}
{
string sql = "update student set xingming=@xingming where xuehao=@xuehao";
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
SqlCommand command = new SqlCommand(sql,conn);
SqlParameter parm = new SqlParameter("@xuehao","001");
command.Parameters.Add(parm);
parm = new SqlParameter("@xingming", "张三");
command.Parameters.Add(parm);
try
{
conn.Open();
return command.ExecuteNonQuery();
}
catch (SqlException ex)
{
return -1;
}
finally
{
conn.Close();
}
}
上一篇: 微信盆友圈里
下一篇: day03_mySQL_总结