Making a generic data layer

  • Thread starter Thread starter SimonH
  • Start date Start date
S

SimonH

Hi all,

I would like to make a generic set of methods that could be called regardless
of the database behind the scenes.

One of the methods I would like would take a string sql statement and an
array of DataParameter objects.

The problem i have is there doesnt seem to be a generic DataParameter class
that I can instantiate. There only seems to be specific implementations like
SQLParamater and so on.

The is an interface called IDataParameter or something to that effect, but
of course I can't instantiate an interface.

I need to be able to work with a non-specific parameter object.

Does anyone know what I could do?

Many thanks all

Kindest Regards
 
Hi Miha

Thank you for the info.

One thing I'm not sure of is what exactly this method returns. The method
signature indicates that an IdbParameter is returned, which is no problem.
But given I can't find any actual implementation class in the .net libraries,
I'm wondering what implementation does it return?

Its somewhat an academic question but I would like to know. It would put
my mind at rest :-)

Thanks again Miha
 
Hi Simon,

It returns the right parameter type, i.e. for SqlCommand it would return an
instance of SqlParameter through IDbDataParameter interface.
Now, you can put your mind at rest :-)
 
Just one small addition to Miha's point.

Even though the parameter type is correct (SqlParameter), the SqldbType
still needs to be correct for the paramter.datatype - this problem manifests
itself on datatypes like Guid.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik




Miha Markic said:
Hi Simon,

It returns the right parameter type, i.e. for SqlCommand it would return
an instance of SqlParameter through IDbDataParameter interface.
Now, you can put your mind at rest :-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

SimonH said:
Hi Miha

Thank you for the info.

One thing I'm not sure of is what exactly this method returns. The method
signature indicates that an IdbParameter is returned, which is no
problem. But given I can't find any actual implementation class in the
.net libraries, I'm wondering what implementation does it return?

Its somewhat an academic question but I would like to know. It would put
my mind at rest :-)

Thanks again Miha
 
Hello Chaps,

I've been thinking about how I would use this method but I'm still not sure
how I would get a IDbParameter out of it.

Could you show me a very brief example? I havent been able to find much on
its use.

Many thanks for your help


Simon
Just one small addition to Miha's point.

Even though the parameter type is correct (SqlParameter), the
SqldbType still needs to be correct for the paramter.datatype - this
problem manifests itself on datatypes like Guid.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
Hi Simon,

It returns the right parameter type, i.e. for SqlCommand it would
return
an instance of SqlParameter through IDbDataParameter interface.
Now, you can put your mind at rest :-)
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com
Hi Miha

Thank you for the info.

One thing I'm not sure of is what exactly this method returns. The
method signature indicates that an IdbParameter is returned, which
is no problem. But given I can't find any actual implementation
class in the .net libraries, I'm wondering what implementation does
it return?

Its somewhat an academic question but I would like to know. It would
put my mind at rest :-)

Thanks again Miha

Hi Simon,

Check out IDbCommand.CreateParameter() method.

Hi all,

I would like to make a generic set of methods that could be called
regardless of the database behind the scenes.

One of the methods I would like would take a string sql statement
and an array of DataParameter objects.

The problem i have is there doesnt seem to be a generic
DataParameter class that I can instantiate. There only seems to be
specific implementations like SQLParamater and so on.

The is an interface called IDataParameter or something to that
effect, but of course I can't instantiate an interface.

I need to be able to work with a non-specific parameter object.

Does anyone know what I could do?

Many thanks all

Kindest Regards
 
Back
Top