有A B C 三个数据库操作语句,利用C#事务处理进行多重操作,如果任何一个语句发生问题,则所有语句都不执行。
C# code
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlCnn;
sqlCmd.Transaction = sqlCnn.BeginTransaction(); //完成事务处理的前期准备工作
try
{
//将用户注册的数据写入数据库
string sqlCmd1 = “insert into User_Login (user_id,user_pwd) values(’” + User_ID + “’,’” + User_PWD + “’)”;
string sqlCmd2 = “insert into User_Data_Basic values(’” + User_ID + “’,’” + User_Name + “’,’” + User_Sex + “’,” + User_Age_Year + “,” + User_Age_Month + “,” + User_Age_Day + “,’’,’’,’’,’’,’’)”;
string sqlCmd3 = “insert into user_data_comunication (user_id) values (’” + User_ID + “’)”;
string sqlCmd4 = “insert into user_data_like (user_id) values (’” + User_ID + “’)”;
string sqlCmd5 = “insert into user_data_schooldata (user_id) values (’” + User_ID +
利用C#事务处理进行多重操作,回滚
最新推荐文章于 2024-05-20 18:11:50 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)