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

Making a generic Parameter class

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

Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
--
"SimonH" <no**@hotmail.com> wrote in message
news:93********************@news.microsoft.com...
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

Jul 21 '05 #2

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

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.
--
"SimonH" <no**@hotmail.com> wrote in message
news:93********************@news.microsoft.com...
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

Jul 21 '05 #3

P: n/a
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.
--
"SimonH" <no**@hotmail.com> wrote in message
news:97********************@news.microsoft.com...
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
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

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.
--
"SimonH" <no**@hotmail.com> wrote in message
news:93********************@news.microsoft.com...
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


Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.