Alternative for DeriveParameters? (ADO.NET 2.0)

  • Thread starter Thread starter James Tharpe
  • Start date Start date
J

James Tharpe

Hello,

My application *only* uses the base-classes (e.g. DbCommand, DbParameter)
for data access and uses DbProviderFactories/DbProviderFactory to create the
concrete classes.

That said, I need the functionality of the DeriveParameters static method
that is part of the various xxxCommandBuilder classes. So my question is: if
I don't know which client is being used, how can I call DeriveParameters?

Is there a non-static equivalent (I couldn't find one)? Or, is there a way
to do this using reflection?

An example would be great, and all help is appreciated.

Thanks!
 
Hi Jame,

The DeriveParameters method is specify for providers. If you don't know the
provider, it's hard to call DeriveParameters method. You can try to cast
the object into desired type and then call DeriveParameter method. There is
no elegant way in this case, AFAIK.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
The DeriveParameters method is specify for providers. If you don't know
the
provider, it's hard to call DeriveParameters method. You can try to cast
the object into desired type and then call DeriveParameter method. There
is
no elegant way in this case, AFAIK.

I can't cast it if I don't know what it is. I did find a workaround though,
using reflection:

DbCommand command = DbFactory.CreateCommand();
// [Snip] code to and assign values to command
Type commandBuilderType = DbFactory.CreateCommandBuilder().GetType();
MethodInfo deriveParametersMethodInfo =
commandBuilderType.GetMethod("DeriveParameters");
if(deriveParametersMethodInfo != null){
object[] deriveParametersMethodArgs = { command };
deriveParametersMethodInfo.Invoke(null, deriveParametersMethodArgs);
}
 
Hi James,

Yes, we can call it through reflection, but the DeriveParameter method is
provider specific. Some other providers might not support that.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top