Oracle.DataAccess.Client.OracleDataReader (ODP.Net) 是否实现 IDataReader 接口?

发布于 2024-08-07 03:22:23 字数 2054 浏览 2 评论 0原文

我是 ODP.Net 的新手,正在尝试将其实施到我们现有的系统中。目前,我们使用OLEDB并使用IDataReader接口从DataReader读取记录。然而,当我们使用ODP.Net使用相同的代码逻辑时,没有选择任何记录。所以,我的问题是,Oracle.DataAccess.Client.OracleDataReader (ODP.Net) 是否实现 IDataReader 接口?如果我尝试使用 OracleDataReader 读取记录而不使用 IDataReader 所选记录。

我正在使用 ODP.Net 10.1.0.4, 甲骨文客户端10g, ASP.Net

编辑:

string lstSelect = fstSelect + pstWhereClause;

IDbConnection lidcConn = fobCreateCon.CreateConnection();
lidcConn.ConnectionString = fstConStr;

IDbCommand lidcComm = fobCreateCon.CreateCommand();
lidcComm.Connection = lidcConn;
lidcComm.CommandText = lstSelect;

if (palParams != null)
{
 for (int i = 0; i < palParams.Length; i++)
 {
  IDbDataParameter lidpParam = fobCreateCon.CreateParameter(
   fstParameterPrefix + "PARA" + i.ToString(), palParams[i]);
  lidcComm.Parameters.Add(lidpParam);
 }
}

IDataReader lidrReader = null;
try
{
 lidcConn.Open();
 lidrReader = lidcComm.ExecuteReader(CommandBehavior.CloseConnection);
 bool lboReturn = lidrReader.Read();
 if (lboReturn)
 {
  fobEmployee.AR_Grace = lidrReader.IsDBNull(0) ? 0 : lidrReader.GetDecimal(0);
  fobEmployee.Card_Issued = lidrReader.IsDBNull(1) ? string.Empty : lidrReader.GetString(1); 
 }
 lidrReader.Close();
 return lboReturn;
}
finally
{
 if (lidrReader != null)
 {
  if (!lidrReader.IsClosed)
   lidrReader.Close();
  lidrReader.Dispose();
 }

 if (lidcConn.State != ConnectionState.Closed)
  lidcConn.Close();
 lidcConn.Dispose();
 lidcComm.Dispose();
}

上面是我们现在使用的代码。它与 OLEDB、SQLClient 完美配合。将此代码与 ODP.Net 一起使用时,不知何故没有返回记录。

我们无法将其更改

OracleDataReader lidrReader = null;
try
{
 lidcConn.Open();
 lidrReader = (OracleDataReader)lidcComm.ExecuteReader(CommandBehavior.CloseConnection);
 if (lidrReader.HasRow)
 {
  lidrReader.Read();
  fobEmployee.AR_Grace = lidrReader.IsDBNull(0) ? 0 : lidrReader.GetDecimal(0);
  fobEmployee.Card_Issued = lidrReader.IsDBNull(1) ? string.Empty : lidrReader.GetString(1); 
 }
 lidrReader.Close();
}

为上面的代码,因为它将涉及超过 300 个数据文件类,并且我们希望此代码适用于其他数据库。有什么帮助吗?

I'm new in ODP.Net and trying to implement it to our existing system. Currently, we are using OLEDB and using IDataReader interface to read a record from DataReader. However, when we use ODP.Net using the same code logic, no records selected. So, my question is, does Oracle.DataAccess.Client.OracleDataReader (ODP.Net) implements IDataReader interface? If i try read the record using OracleDataReader without using IDataReader the record selected.

I'm using ODP.Net 10.1.0.4,
Oracle Client 10g,
ASP.Net

Edit:

string lstSelect = fstSelect + pstWhereClause;

IDbConnection lidcConn = fobCreateCon.CreateConnection();
lidcConn.ConnectionString = fstConStr;

IDbCommand lidcComm = fobCreateCon.CreateCommand();
lidcComm.Connection = lidcConn;
lidcComm.CommandText = lstSelect;

if (palParams != null)
{
 for (int i = 0; i < palParams.Length; i++)
 {
  IDbDataParameter lidpParam = fobCreateCon.CreateParameter(
   fstParameterPrefix + "PARA" + i.ToString(), palParams[i]);
  lidcComm.Parameters.Add(lidpParam);
 }
}

IDataReader lidrReader = null;
try
{
 lidcConn.Open();
 lidrReader = lidcComm.ExecuteReader(CommandBehavior.CloseConnection);
 bool lboReturn = lidrReader.Read();
 if (lboReturn)
 {
  fobEmployee.AR_Grace = lidrReader.IsDBNull(0) ? 0 : lidrReader.GetDecimal(0);
  fobEmployee.Card_Issued = lidrReader.IsDBNull(1) ? string.Empty : lidrReader.GetString(1); 
 }
 lidrReader.Close();
 return lboReturn;
}
finally
{
 if (lidrReader != null)
 {
  if (!lidrReader.IsClosed)
   lidrReader.Close();
  lidrReader.Dispose();
 }

 if (lidcConn.State != ConnectionState.Closed)
  lidcConn.Close();
 lidcConn.Dispose();
 lidcComm.Dispose();
}

Above is the code we using right now. It works perfectly with OLEDB, SQLClient. Somehow no record return when using this code with ODP.Net.

We manage to select the record when change to this

OracleDataReader lidrReader = null;
try
{
 lidcConn.Open();
 lidrReader = (OracleDataReader)lidcComm.ExecuteReader(CommandBehavior.CloseConnection);
 if (lidrReader.HasRow)
 {
  lidrReader.Read();
  fobEmployee.AR_Grace = lidrReader.IsDBNull(0) ? 0 : lidrReader.GetDecimal(0);
  fobEmployee.Card_Issued = lidrReader.IsDBNull(1) ? string.Empty : lidrReader.GetString(1); 
 }
 lidrReader.Close();
}

We impossible to change it to the above code cause it will involve more than 300 data file classes and we want this code working for other databases. Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北渚 2024-08-14 03:22:23

如果我们谈论的是 System.Data.IDataReader,答案是肯定的。事实上,OracleDataReader 继承自抽象类 System.Data.Common.DbDataReader,而抽象类又继承自 System.Data.IDataReader。

换句话说,Oracle 与 ADO.NET 配合得很好,并且应该或多或少与其他 ADO.NET 提供程序完全相同。

虽然我没有尝试过 10.2.x 之前的版本,但我怀疑事情是否发生了重大变化。我在使用 OracleDataReader 时没有遇到任何问题。

If we're talking about System.Data.IDataReader, the answer is yes. In fact, OracleDataReader inherits from the abstract class System.Data.Common.DbDataReader which in turn inherits from the System.Data.IDataReader.

In other words, Oracle plays nice with the ADO.NET and should work more or less exactly like the other ADO.NET providers.

I have not tried with the versions prior to 10.2.x though, but I doubt things have changed significantly. I have had no problems with the OracleDataReader.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文