By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

Converting IDataParameter to IDbDataParameter

P: n/a
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.

May 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
And what's the error did u get? Could you demonstrate your code

"Doug" wrote:
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

May 17 '06 #2

P: n/a
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 :(
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Doug" <dn******@dtgnet.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
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.

May 17 '06 #3

P: n/a
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.

May 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.