David

David

  • NA
  • 13
  • 0

Database Parameters - OleDBType

Aug 10 2008 7:17 AM

Hi all,

I have a framework that is used for connecting to the database. It works fine, however I want to introduce the technique of binding variables into it (=using database parameters). The framework uses the microsoft oledb driver (but i have the same issue with the oracle driver) on an oracle 10 database. In the framework there's a method that looks like:

public void SomeMethod(object[] parameters)

{

      ...

      foreach (object param in parameters)

      {

         oledbcommand.Parameters.Add(param)

      }

      ...

}

 

Suppose we have 1 parameter (type string) that will be used in "select * from country where id = ?" and the database field country.id has type varchar2(10), this works fine. (System.String is automatically adressed as a OleDbType.Varchar2 parameter by the .NET framework)

However if the database field country.id has type char(10), I don't receive database exceptions (ora faults) and I don't receive unexpected exceptions, however the existing database record will not be retrieved. A solution for this is using the command

oledbcommand.Parameters.Add(new OleDbParameter(name, OleDbType.Char).Value = ...);

This will retrieve the database record, however I can't implement this in my framework. The SomeMethod-method is used for executing every select in my applications and doesn't know the type of the database field (a string could be varchar2, char, nvarchar, clob, ....)

Somebody knows how to handle this issue? Thanx for your response


Answers (3)