我可以在 odp.net 和 Oracle 8i 中使用绑定变量吗?
由于缺乏测试环境,我需要知道以下场景是否可行:
我已经安装了 Oracle Data Provider for .Net 版本 9.2.0.4。在生产中,我必须从我的 C# 应用程序与两个数据库(Oracle 8i 和 9i)进行通信。
Oracle 8i 在这种情况下支持绑定变量吗?
我可能会使用类似于以下的代码:
提前致谢!
OracleCommand cmd = con.CreateCommand();
OracleTransaction txn = con.BeginTransaction();
try {
cmd.CommandText = "update MayJun2009 " +
"set balance = balance + :1 " +
"where account_id = :2";
OracleParameter pBalance = new OracleParameter();
pBalance.OracleDbType = OracleDbType.Int32;
OracleParameter pAccount = new OracleParameter();
pAccount.OracleDbType = OracleDbType.Int32;
cmd.Parameters.Add(pBalance);
cmd.Parameters.Add(pAccount);
pBalance.Value = -500;
pAccount.Value = 1;
cmd.ExecuteNonQuery();
pBalance.Value = 500;
pAccount.Value = 2;
cmd.ExecuteNonQuery();
txn.Commit();
}
catch (OracleException ex) {
txn.Rollback();
}
due to the lack of an testing environment I need to know if the following scenario will work:
I have installed the Oracle Data Provider for .Net version 9.2.0.4. In production I'll have to communicate from my C# application with two Databases, an Oracle 8i and 9i.
Does Oracle 8i support Bind Variables in this scenario?
I'm likely to use code similar to the following:
Thanks in advance!
OracleCommand cmd = con.CreateCommand();
OracleTransaction txn = con.BeginTransaction();
try {
cmd.CommandText = "update MayJun2009 " +
"set balance = balance + :1 " +
"where account_id = :2";
OracleParameter pBalance = new OracleParameter();
pBalance.OracleDbType = OracleDbType.Int32;
OracleParameter pAccount = new OracleParameter();
pAccount.OracleDbType = OracleDbType.Int32;
cmd.Parameters.Add(pBalance);
cmd.Parameters.Add(pAccount);
pBalance.Value = -500;
pAccount.Value = 1;
cmd.ExecuteNonQuery();
pBalance.Value = 500;
pAccount.Value = 2;
cmd.ExecuteNonQuery();
txn.Commit();
}
catch (OracleException ex) {
txn.Rollback();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,该示例应该使用绑定变量,无论是 Oracle 8 还是 9i 都不重要。您可以进行数据库跟踪来进行确定。 C# 绑定的另一个示例如下:
构建 Oracle .NET 应用程序的数据提供程序
Yes, that example should be using bind variables, shouldn't matter whether it is Oracle 8 or 9i. You could do a database trace to verify for certain. Another example of binds for C# is here:
Building an Oracle Data Provider for .NET Application
如果您的应用程序使用 9iR2 客户端或更高版本(您的情况似乎如此),您可以连接到 Oracle8i(甚至直接 Oracle8)数据库。
Providing your application is using a 9iR2 client or higher, which appears to be true in your case, you can connection to Oracle8i (or even straight Oracle8) databases.