Hi,
I have a generic function that executes a stored procedure & returns a
data table.
Code:
===
public static DataTable ExecuteStoredProcedure(string
strProc,SqlParameter[] paramArray)
{
SqlCommand command = new SqlCommand(strProc, connection);
command.CommandType = CommandType.StoredProcedure;
for(int i=0;i<paramArray.Length;i++)
command.Parameters.Add(paramArray[i]);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
connection.Close();
return(table);
}
The stored proc is used for paging, it takes page number & page size as
input parameters & returns the records for a particular page.
This code works fine and I use the data table returned by this function
to bind a datagrid and also to do some other stuff during the
itemdatabound of the grid.
Now I want the stored proc to return the total number of records (it
returns only n records of a particular page) in the database. I can not
use data table's rowcount coz it will always give the page size 10),
not the total number of records in the database.
So I added an OUTPUT parameter to the stored proc which returns the
total number of records as well.
Now my problem is how do I change this function to take care of this
output parameter.
I can add the output parameter to the parameter array and execute the
stored proc but the data table will not contain the output paramerter's
value. I can get it using command.parameter("@out") but then I can not
return both the data table & this value from the function.
Is there any way I can tweak this function to return both the values? I
want the calling function to receive both the output paramer's value
and also the records returned by the stored proc.
Thanks,
Ashish.