Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function w/ Multiple (x) Parameters

Status
Not open for further replies.

anonim1

Programmer
Dec 10, 2004
108
US
I have an ASP.NET application with many pages. A lot of the pages make calls to a MSSQL database to retrieve data. On each page, I have functions that connect to the DB, execute a T-SQL statement or stored procedure, and return values, etc.

I want to avoid having to re-write a lot of the same code in the function across multiple pages. Therefore, I am thinking of creating a new class file and adding functions to connect to the database there, and then calling these functions from other ASPX pages. Here is the problem then...

Let's say that I want to call a stored procedure that returns a scalar value. So my function prototype would be something to the effect of:

private string GetScalarValue(string storedProc, string returnValue, SqlParameter sqlParam) { ... }

Now, what if I have two parameters that I want to pass? I could have an overloaded function that takes two SqlParameters.

But What if I have x parameters? Having my programming background in C++, my thought is to create an array of SqlParameters (SqlParameter paramList = new SqlParameter[count]) and use a for() loop to add each parameter. While this will probably work, I was hoping there was a built-in mechanism to do this. I remember reading or hearing about collections a while back. Is this what I need to be using? Arrays seem old-school to me.

Any suggestions are appreciated.

Varol
 
How I have done this is set up a database class that has functions for returning datatables/datasets...to these functions i simply send in a SQLCommand object.

then in my other class i have different functions for different information needed. Setting up the SQLCommand: text, type, and parameters...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top