SqlConnection myconnection = new SqlConnection(SqlDapperHelper.connStrWrite);myconnection.Open();SqlTransaction myTrans = myconnection.BeginTransaction();SqlCommand myCommand = new SqlCommand();myCommand.Connection = myconnection;myCommand.Transaction = myTrans;myCommand.CommandText = "select * from Categories where categoryid=1";myCommand.ExecuteNonQuery();myTrans.Commit();修改该数据行是有排他锁的 但是查询就没有 默认的共享锁吗?我该怎么在c# 代码里在开启事务查询时强制给查询的数据加排他锁???
1 回答
慕后森
TA贡献1802条经验 获得超5个赞
使用 TABLOCKX
myCommand.CommandText = "select * from Categories WITH(TABLOCKX) where categoryid=1";
- 1 回答
- 0 关注
- 905 浏览
添加回答
举报
0/150
提交
取消