我在IronPython中有一个更新和插入脚本,所以当我通过它运行它们时
ExecuteNonQuery()
它返回1个受影响的行(正如预期的那样),但是当我查看db(或运行select
查询)时,没有任何更改。
def update(pConnection, transaction, serialName, serial_counter):
query = """ UPDATE [EM_DEMO].[dbo].[tblCounter]
SET [Counter] = @counter
WHERE [ChiaveTabella] = @serial_column
""";
print 'query: ', query; # DEBUG INFO
cmd = pConnection.CreateCommand();
cmd.Transaction = transaction;
cmd.CommandText = query;
cmd.Parameters.AddWithValue('@counter', serial_counter.ToString());
cmd.Parameters.AddWithValue('@serial_column', serialName);
rowsAffected = cmd.ExecuteNonQuery();
if not rowsAffected == 1:
print 'Error during update! rows affected:', rowsAffected;
return False;
else:
print 'Complete!';
return True;
但是当我从本地C#运行相同的代码时:它运行良好! 任何人都可以帮助我:问题是什么?
答案 0 :(得分:0)
忘记手动提交更改(在本机C#中工作而不提交)和抛出异常,因此每次执行后都需要transaction.Commit()
。
# ...
rowsAffected = cmd.ExecuteNonQuery();
transaction.Commit();
# ...