本文整理汇总了C#中NuoDb.Data.Client.NuoDbConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# NuoDbConnection.BeginTransaction方法的具体用法?C# NuoDbConnection.BeginTransaction怎么用?C# NuoDbConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuoDb.Data.Client.NuoDbConnection
的用法示例。
在下文中一共展示了NuoDbConnection.BeginTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestUpdateWithGeneratedKeys
public void TestUpdateWithGeneratedKeys()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
connection.Open();
DbTransaction transaction = connection.BeginTransaction();
DbCommand updateCommand = connection.CreateCommand();
updateCommand.CommandText = "update hockey set number = 99 where team = 'Bruins'";
DbDataReader reader = updateCommand.ExecuteReader();
Assert.IsNotNull(reader, "The command should return a generated keys recordset");
Assert.IsFalse(reader.Read(), "The generated keys recordset should be empty");
transaction.Rollback();
}
}
示例2: TestPreparedInsertWithGeneratedKeys2
public void TestPreparedInsertWithGeneratedKeys2()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
connection.Open();
DbTransaction transaction = connection.BeginTransaction();
DbCommand maxIdCmd = connection.CreateCommand();
maxIdCmd.CommandText = "select max(id) from hockey";
int maxId = (int)maxIdCmd.ExecuteScalar();
DbCommand updateCommand = connection.CreateCommand();
updateCommand.CommandText = "insert into hockey (number, name) values (?, ?)";
updateCommand.Prepare();
updateCommand.Parameters[0].Value = 99;
updateCommand.Parameters[1].Value = "xxx";
DbDataReader reader = updateCommand.ExecuteReader();
Assert.IsNotNull(reader, "The command should return a generated keys recordset");
Assert.IsTrue(reader.Read(), "There must be at least one ID in the generated keys recordset");
int lastId = (int)reader.GetValue(0);
Assert.IsTrue(lastId > maxId, "The generated ID must be greater than the existing ones");
DbCommand selectCommand = connection.CreateCommand();
selectCommand.CommandText = "select name from hockey where id = ?";
selectCommand.Parameters.Add(lastId);
string value = (string)selectCommand.ExecuteScalar();
Assert.AreEqual("xxx", value);
transaction.Rollback();
}
}
示例3: TestTransactions
public void TestTransactions()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
connection.Open();
DbTransaction transaction = connection.BeginTransaction();
DbCommand countCommand = connection.CreateCommand();
countCommand.CommandText = "select count(*) from hockey";
DbCommand updateCommand = connection.CreateCommand();
updateCommand.CommandText = "insert into hockey (number, name) values (99, 'xxxx')";
int count1 = (int)countCommand.ExecuteScalar();
updateCommand.ExecuteNonQuery();
int count2 = (int)countCommand.ExecuteScalar();
Assert.AreEqual(count2, count1 + 1);
transaction.Rollback();
int count3 = (int)countCommand.ExecuteScalar();
Assert.AreEqual(count3, count1);
}
}
示例4: TestInsertWithGeneratedKeys
public void TestInsertWithGeneratedKeys()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
connection.Open();
DbTransaction transaction = connection.BeginTransaction();
DbCommand maxIdCmd = connection.CreateCommand();
maxIdCmd.CommandText = "select max(id) from hockey";
int maxId = (int)maxIdCmd.ExecuteScalar();
DbCommand updateCommand = connection.CreateCommand();
updateCommand.CommandText = "insert into hockey (number, name) values (99, 'xxxx')";
DbDataReader reader = updateCommand.ExecuteReader();
Assert.IsNotNull(reader, "The command should return a generated keys recordset");
Assert.IsTrue(reader.Read(), "There must be at least one ID in the generated keys recordset");
int lastId = (int)reader.GetValue(0);
Assert.IsTrue(lastId > maxId, "The generated ID must be greater than the existing ones");
transaction.Rollback();
}
}