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

How to Overload the Add Method of the ParameterCollection?

P: n/a
Hi All,

I'm writing a data access class in which I expose an SQlClient.SQLCommand's
Parameters Collection via a property.

How would I go about overloading the parameters.add method with one of my
own?

The reason I wish to do this is be able to supply on one line the Name,
Type, Direction, Size and Value and as none of the current methods do this.

Thanks

Alex
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alex,

I can't answer your question, but I can question your question.

If I were doing it, I wouldn't want to override the Parameters collection's
Add property. In order to override the Add property, you'd have to create
your own class that inherits from the Collection class, and then give your
new class an Add property. That seems to me like it would be too much work
for too little benefit. Also, and in my opinion more important, you'd be
fundamentally changing the meaning of the Add property. You wouldn't be
able to add a single item to an instance of your derived collection class.
When you derive a class, you are saying that your derived class is your base
class, with some additions and possibly some different ways of doing things.
Your derived class wouldn't have an Add method that matches its base class.
You'd be violating the implied contract you accepted when you chose to use
inheritance.

Just give your data access class an AddEverything() method that calls the
command object's parameter collectoin's Add method five times.

Rob
Nov 20 '05 #2

P: n/a
Thanks Rob.......

After reading what you've replyed with i've taken this approach.
My Data Access component has an AddParameter function which creates the
parameter, adds it to the command object and returns it.
This allows the parameter properties to passed all in one line, and on the
same can return a reference to the created parameter.
In the event of a stored proc with output parameters running, then the user
can obtain the return values, from the parameter reference.

Bloody tidy.

Thanks Again.
"Rob Richardson" <th*****@n2net.net> wrote in message
news:eB*************@TK2MSFTNGP12.phx.gbl...
Alex,

I can't answer your question, but I can question your question.

If I were doing it, I wouldn't want to override the Parameters collection's Add property. In order to override the Add property, you'd have to create
your own class that inherits from the Collection class, and then give your
new class an Add property. That seems to me like it would be too much work for too little benefit. Also, and in my opinion more important, you'd be
fundamentally changing the meaning of the Add property. You wouldn't be
able to add a single item to an instance of your derived collection class.
When you derive a class, you are saying that your derived class is your base class, with some additions and possibly some different ways of doing things. Your derived class wouldn't have an Add method that matches its base class. You'd be violating the implied contract you accepted when you chose to use
inheritance.

Just give your data access class an AddEverything() method that calls the
command object's parameter collectoin's Add method five times.

Rob

Nov 20 '05 #3

P: n/a
He didn't say Override he said Overload.

Function Add(ByVal Item as Object) As Integer
Return MyBase.Add(Item)
End Function

'This function Overloads the one above it.
Function Add(Caption as String, Value As Integer) As Integer
Dim MyItem as New MyType
MyItem.Text = Caption
MyItem.IntegerVariable = Value
Return MyBase.Add(MyItem)
End Function

The original Method is still in the Class, but you also now have a new
Overloaded Method.

The Method you described would be AddRange() not Add()

"Rob Richardson" <th*****@n2net.net> wrote in message
news:eB*************@TK2MSFTNGP12.phx.gbl...
Alex,

I can't answer your question, but I can question your question.

If I were doing it, I wouldn't want to override the Parameters collection's Add property. In order to override the Add property, you'd have to create
your own class that inherits from the Collection class, and then give your
new class an Add property. That seems to me like it would be too much work for too little benefit. Also, and in my opinion more important, you'd be
fundamentally changing the meaning of the Add property. You wouldn't be
able to add a single item to an instance of your derived collection class.
When you derive a class, you are saying that your derived class is your base class, with some additions and possibly some different ways of doing things. Your derived class wouldn't have an Add method that matches its base class. You'd be violating the implied contract you accepted when you chose to use
inheritance.

Just give your data access class an AddEverything() method that calls the
command object's parameter collectoin's Add method five times.

Rob

Nov 20 '05 #4

P: n/a
Mick,

Drat, drat, drat. You're right, of course. Thanks for the correction.

Rob

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:On**************@TK2MSFTNGP12.phx.gbl...
He didn't say Override he said Overload.

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.