Converting IDataParameter to IDbDataParameter

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

Hi,

I am using some code that was written for common use within my company
that has a Parameter object that inherits from IDataParameter.
However, a whole other piece of code that we use for querying the
database has methods in it that need to take in a variable of type
IDbDataParameter (yes, I know, communication was not evident here!).

Anyways, is there anyway to convert an IDataParameter value to an
IDbDataParameter one without writing a ton of code? I tried a simple
cast and it failed.
 
And what's the error did u get? Could you demonstrate your code

Doug said:
Hi,

I am using some code that was written for common use within my company
that has a Parameter object that inherits from IDataParameter.
However, a whole other piece of code that we use for querying the
database has methods in it that need to take in a variable of type
IDbDataParameter (yes, I know, communication was not evident here!).

Anyways, is there anyway to convert an IDataParameter value to an
IDbDataParameter one without writing a ton of code? I tried a simple
cast and it failed.

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hi,

Why using a IDbDataParameter ? IIRC this is especific to VB.net

You can convert an IDbDataParameter to IDataParameter , the opposite don't
think that is possible, you would have to manually create it :(
 
Sure:

IDataParameter[] parameters = new IDataParameter[1];
parameters[0] = new Parameter("@PRGRM_ENTR_ID", DbType.Int32,
programId);
return (IDbDataParameter[])parameters;

The "new Parameter" line is referring to our common component that has
a Parameter class that inherits from IDataParameter. However I need an
IDbDataParameter to use in a method a few lines later (for querying)
and so am trying to cast it as you can see.

I get a "Specfied Cast Not Valid" error when I try to do what I'm doing
above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top