我在 C# 中有一个方法,它执行一些查询以插入事务内的数据库中。
我想要做的是一个循环插入几个“电话号码”
// Creates the transaction
dbTransaction = dbConnection.DbConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
// Creates the sql command
dbCommand = factory.CreateCommand();
dbCommand.Connection = dbConnection.DbConnection;
dbCommand.Transaction = dbTransaction;
...逻辑的东西
// Inserts the phone
foreach (PlacePhoneDTO placePhoneDTO in placePhoneList)
{
dbCommand.CommandText = sqlStatementPhone.ToString();
// Adds the parameters
AddParameter<int>("@PlaceID", placeID, ref dbCommand);
AddParameter<string>("@PhoneNumber", placePhoneDTO.phoneNumber, ref dbCommand);
dbCommand.ExecuteNonQuery();
}
dbTransaction.Commit();
第二次执行循环失败
非常感谢