I have a SQL Server stored procedure that has 3 selects and returns 3 different data tables. I want to save all these tables into their own Viewbags or ViewData in ASP.NET MVC using C#
Calling the SQL Server stored procedure:
exec getData 1, '#244'
This returns 3 rows with different row and column numbers from grouping the data
C# model class - everything has been initialized
public void financeData(int id, string purchase_number)
{
con.ConnectionString = constr;
string query = "getData";
SqlCommand command = new SqlCommand(query, con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@purchase_number", purchase_number);
DataTable top_purchases = new DataTable();
DataTable transaction_summary = new DataTable();
DataTable maximum_amount = new DataTable();
// code to read the tables into different lists
con.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// code to read the tables into different lists
}
}
}
Is there a way to use one procedure for the different data sets since I need to add more procedures with similar queries?