I have a stored procedure in SQL Server which returns seven result sets. I would like to call this stored procedure from ASP.NET and populate seven GridViews on my ASP.NET page with the results. I am using a SqlDataReader to get the data, however I'm struggling with the C# code to fill the GridViews.
I have created a DAL class to get the data and I have this method in there:
public SqlDataReader CheckDataIntegrity()
{
SqlCommand cmd = new SqlCommand("cc.DataCheck");
return MultipleResults(cmd);
}
The helper method MultipleResults looks like this:
private SqlDataReader MultipleResults(SqlCommand cmd)
{
SqlConnection con = new SqlConnection(_connectionString);
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
con.Close();
return dr;
}
I'm trying to call the component on my page with something like:
private void FillGridViews()
{
DBUtil DB = new DBUtil();
using (SqlDataReader dr = DB.CheckDataIntegrity())
{
if (dr.HasRows)
{
while (dr.Read())
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
}
}
}
I did search the web for an example of this, but couldn't find anything.
Do you know of a resource, or have a small example to share?
Thanks.