当前位置: 首页>>代码示例>>C#>>正文


C# NuoDbConnection.BeginTransaction方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:17,代码来源:TestFixture.cs

示例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();
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:32,代码来源:TestFixture.cs

示例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);
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:25,代码来源:TestFixture.cs

示例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();
            }
        }
开发者ID:rsantosdev,项目名称:nuodb-dotnet,代码行数:23,代码来源:TestFixture.cs


注:本文中的NuoDb.Data.Client.NuoDbConnection.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。