在.NET中如何使用Oracle数据库事务(4)
点击次数:86 次 发布日期:2008-11-06 08:09:34 作者:源代码网
|
将 OracleCommand 对象的 CommandText 属性设为向表 product_types 中添加一行的第一条 INSERT 语句。 在 C# 中: myOracleCommand.CommandText = "INSERT INTO product_types (" + " product_type_id, name" + ") VALUES (" + " 3, "Magazine"" + ")"; 在 VB.NET 中: myOracleCommand.CommandText = _ "INSERT INTO product_types (" & _ " product_type_id, name" & _ ") VALUES (" & _ " 3, "Magazine"" & _ ")" 第 5 步 使用 OracleCommand 对象的 ExecuteNonQuery() 方法运行 INSERT 语句。 在 C# 中: myOracleCommand.ExecuteNonQuery(); 在 VB.NET 中: myOracleCommand.ExecuteNonQuery() 第 6 和第 7 步 将 OracleCommand 对象的 CommandText 属性设为向表 Products 中添加一行的第二条 INSERT 语句,并运行它。 在 C# 中: myOracleCommand.CommandText = "INSERT INTO products (" + " product_id, product_type_id, name, description, price" + ") VALUES (" + " 5, 3, "Oracle Magazine", "Magazine about Oracle", 4.99" + ")"; myOracleCommand.ExecuteNonQuery(); 在 VB.NET 中: myOracleCommand.CommandText = _ "INSERT INTO products (" & _ " product_id, product_type_id, name, description, price" & _ ") VALUES (" & _ " 5, 3, "Oracle Magazine", "Magazine about Oracle", 4.99" & _ ")" myOracleCommand.ExecuteNonQuery() 第 8 步 使用 OracleTransaction 对象的 Commit() 方法提交数据库中的事务。 在 C# 中: myOracleTransaction.Commit(); 在 VB.NET 中: myOracleTransaction.Commit() 软件开发网 www.mscto.com 在完成 Commit() 方法之后,由 INSERT 语句添加的两行将在数据库中永久记录。 第 9 步 使用 Close() 方法关闭 OracleConnection 对象。 在 C# 中: myOracleConnection.Close(); 在 VB.NET 中: myOracleConnection.Close() 源代码网推荐 源代码网供稿. |
