Making a generic Parameter class

  • 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
 
SqlParameter is an implementation of an 'Adapter' pattern. This allows
things like DataAdapter and DataReader to be able to use generic methods for
using these objects without concern for which database lies underneath it.
If you have a database (that is not either SQL Server or Oracle) that you
want to access, simply creating objects that meets the same interface
(MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable) will
allow your methods to be used by the higher-level database objects.

In other words, .Net already does this for you.

What .Net doesn't do is provide you with an abstract factory. You can
easily write one that returns an object of type IDbDataParameter when you
want to create a new parameter object. Then you can use your factory to
create generic objects, and in fact, can use these objects as generic ones
(cross db) without knowing if the factory is connecting you to SQL Server
objects, Oracle objects, or another set of Adapter objects.

Please read up on the Abstract Factory pattern.

http://www.dofactory.com/Patterns/PatternAbstract.aspx

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Nick,

Thanks for your reply.

I've used the adapter and abstract factory patterns before.

What I need to know is if there is already a generic implementation class
for the IdbParameter interface that I can use?

Is the case basically that I need to make my own simple parameter implementation?
I'd rather not if there was already a simple implementation already as it
make my datalayer more complicated.

If I have to implement though, I'll just have to :-)

Thanks for your help

Kindest Regards
 
Hello Simon,

What new database system do you want to abstract?

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
Back
Top