Binding to Datagrid

J

jasmine

hi friend

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 her

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()
d

Grid1.DataSource=myreader
Grid1.DataBind()

while (myreader.NextResult())
myreader.Close()
conn.Close()

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

lostinet

you should join the two tables
use SqlDataAdapter.Fill in to a DataSet ds first
DataTable table1=ds.Tables[0];
DataTable table2=ds.Tables[1];
foreach(DataRow row in table2.Rows)
{
table1.ImportRow(row);
}
Grid1.DataSource=table1.DefaultView;
Grid1.DataBind();

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top