我无法使用以下代码片段回滚,需要帮助:
import clr
import sys
clr.AddReference('System.Data')
from System.Data.SqlClient import SqlConnection, SqlParameter, SqlTransaction
conn_string = "****"
connection = SqlConnection(conn_string)
connection.Open()
createuser = connection.CreateCommand()
createuser.CommandText = "****"
try:
reader = createuser.ExecuteReader()
reader.Close()
except:
reader.Rollback()
谢谢!
我现在明白了,但是现在我遇到了一个问题,它需要一个字符串,但是如果我将 SQL 查询字符串作为参数放入,我就无法执行参数化值:
createuser.CommandText = "****"
createuser.Parameters.AddWithValue("@Username", username);
usertransaction = connection.BeginTransaction(createuser)
try:
usertransaction.Commit()
except:
usertransaction.Rollback()