473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Making a generic Parameter class

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
3 2293
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yaniv.golan | last post by:
Hi, Either I am missing something, or there is a compiler bug in the way inheritance from generic s is treated. In the following code, class c2 inherits from c1_generic. c1_generic has T as a...
3
by: SimonH | last post by:
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...
4
by: Hyun-jik Bae | last post by:
Is that not allowed to assume generic type numeric type? As far as I've tried, I got an error with the following code: public class AAA<T> { public int Foo(T a) { return a; // error: Cannot...
6
by: Milsnips | last post by:
Hi there, this is what i'm trying to achieve, i have separate identical classes for SqlClient, OracleClient, Odbc and OleDb, what i want is to create a Wrapper class that calls any of these 4...
1
by: interX | last post by:
Hi I'm new in VC++ and have a question to generics. I have a generic class, which contains an array of the generic type. This array I can pin and then I would like to get an unmanaged pointer to...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
1
by: DotNetNewbie | last post by:
Hi, In the source code for System.Web.MVC the generic class is defined as: public class ViewPage<TViewData: ViewPage I want to create my own custom ViewPage class, and inherit from the...
9
by: tadmill | last post by:
Is it possible to pass a generic parameter of the same class to to its constructor, where the "T" type passed in the constructor is different than the "T" type of the instanced class? ie, ...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.