The code you posted works great. I have another related question. What is the best way to to do the databinding when I need to do it multiple times on one page. I actually have 5 grids on the page, each using a different stored procedure (but the same UserID parameter) to pull data from different tables. I guess I'm looking for the cleanest, best way to do it. And where is the best place to close the connection?
private void BindData()
using (SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyProject"].ConnectionString))
SqlCommand cm = new SqlCommand("MyStoredProcedure", cn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@UserID", SqlDbType.Int).Value = SessionHelper.GetUserId();
using (SqlDataReader dr = cm.ExecuteReader())
MyGrid.DataSource = dr;