How to Overload the Add Method of the ParameterCollection?

  • Thread starter Thread starter Alex Stevens
  • Start date Start date
A

Alex Stevens

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
 
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
 
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.
 
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()
 
Mick,

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

Rob

"Mick Doherty"
 
Back
Top