Binding to DataGrid

G

Guest

hi friends

I am developing web application in .NET using c#. I encounter a problem in binding the results to the datagrid. I have a storeprocedure that produce 2 results set. I need to read the results and bind it in a datagrid control. But i am able to bind only one result set eventhough i am using the datareader.next result(); Can any one of you help me? My code follows here

SqlCommand cmd1 = new SqlCommand("Testpaper_DHistory",conn);
cmd1.CommandType=System.Data.CommandType.StoredProcedure;
SqlParameter myparam = cmd1.Parameters.Add(new SqlParameter("@nric",SqlDbType.VarChar,20));
myparam.Value = Session["userid"].ToString();
SqlDataReader myreader = cmd1.ExecuteReader();
do
{
Grid1.DataSource=myreader;
Grid1.DataBind();
}
while (myreader.NextResult());
myreader.Close();
conn.Close();


Even I tried Grid1.Datasource = cmd1.ExecuteReader(); It is also not working.
 
M

Miha Markic

Hi jasmine,

You can bind only one datatable (result) to grid at a time.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

jasmine said:
hi friends

I am developing web application in .NET using c#. I encounter a problem in
binding the results to the datagrid. I have a storeprocedure that produce 2
results set. I need to read the results and bind it in a datagrid control.
But i am able to bind only one result set eventhough i am using the
datareader.next result(); Can any one of you help me? My code follows here
SqlCommand cmd1 = new SqlCommand("Testpaper_DHistory",conn);
cmd1.CommandType=System.Data.CommandType.StoredProcedure;
SqlParameter myparam = cmd1.Parameters.Add(new SqlParameter("@nric",SqlDbType.VarChar,20));
myparam.Value = Session["userid"].ToString();
SqlDataReader myreader = cmd1.ExecuteReader();
do
{
Grid1.DataSource=myreader;
Grid1.DataBind();
}
while (myreader.NextResult());
myreader.Close();
conn.Close();


Even I tried Grid1.Datasource = cmd1.ExecuteReader(); It is also not working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top