473,608 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2314
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
(MarshalByRefOb ject, IDbDataParamete r, 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 IDbDataParamete r 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.c om> wrote in message
news:93******** ************@ne ws.microsoft.co m...
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 (MarshalByRefOb ject,
IDbDataParamete r, 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 IDbDataParamete r 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.c om> wrote in message
news:93******** ************@ne ws.microsoft.co m...
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.c om> wrote in message
news:97******** ************@ne ws.microsoft.co m...
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 (MarshalByRefOb ject,
IDbDataParamete r, 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 IDbDataParamete r 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.c om> wrote in message
news:93******** ************@ne ws.microsoft.co m...
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
1630
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 generic paramter, and in the inheritance, class c2 specifies c3_T as the value of this parameter. class c1_generic defines 2 constructors, 1 of them taking 1 parameter.
3
298
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 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
4
9159
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 implicitly convert type 'T' to 'int' } }
6
3463
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 based on the user connection.... so what i had in mind was something like this: Application starts and prompts user to create a database connection.
1
3424
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 it. Therefore I wanted to creat a class member which represents the pointer to the array. Unfortunately I get the folowring compile error for the code beneath: error C3229: 'DataType *' : indirections on a generic type parameter
9
5838
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 the static Parse method of the conversion class. if (InValue is string) return T.Parse((string)InValue); else return base.ConvertFrom(context, culture, InValue);
1
3168
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 generic type.
9
3142
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, public class SomeList<T> { public SomeList(SomeList<TthisSomeList)
50
4461
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): //------------------------------------------------------------------ template<typename Data_t> class SmartPointer { Data_t* data; void(*deleterFunc)(Data_t*);
0
8059
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8000
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8470
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8330
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.