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
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