Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Binding to Datagrid

Reply
Thread Tools

Binding to Datagrid

 
 
jasmine
Guest
Posts: n/a
 
      12-09-2003
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.StoredPro cedure
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.

 
Reply With Quote
 
 
 
 
lostinet
Guest
Posts: n/a
 
      12-09-2003
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" <> дÈëÓʼþ
news:9F10BDD9-CD92-46D0-8675-...
> 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.StoredPro cedure;
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding - how to stop initial binding Amit ASP .Net 6 10-24-2006 08:06 AM
pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe) kogrover@gmail.com Python 2 10-20-2006 04:08 PM
Complex data binding question, binding child objects of a custom collection. JcFx ASP .Net Datagrid Control 0 06-01-2005 04:01 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM
value binding and function binding Vivek Nallur Ruby 0 09-25-2003 02:52 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57