Home All Groups Group Topic Archive Search About

Alternative for DeriveParameters? (ADO.NET 2.0)

Author
7 Nov 2005 6:56 PM
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!


Author
8 Nov 2005 3:37 AM
Kevin Yu [MSFT]
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."
Author
11 Nov 2005 3:25 PM
James Tharpe
> 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);
}

Author
12 Nov 2005 3:29 AM
Kevin Yu [MSFT]
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."

AddThis Social Bookmark Button