Handling dataset and gridview

Posted by Thiru under ASP.NET on 9/5/2011 | Points: 10 | Views : 1834 | Status : [Member] | Replies : 2
Hi can anyone give a sample code to fulfill my expect result:

Lets have an example database having two tables named: tblcustomer and tblorder
relationship field between two tables are custid
fields in tblcustomer: cstid, name, city
fields in tblorder: odr_no, cstid, date,prdid,qty

Using dataset/datatable, i need to display selected customer details from tblcustomer and his order details in gridview

my code is:
cmd = New MySqlCommand("select * from tblcustomer; select * from tblorder;", con)
adp = New MySqlDataAdapter(cmd)
Note: i have taken all records from both table. Now i want to show only selected customer details and his order details in gridview.
// how to do this ?

following code will display all records:
GridView1.DataSource = dset.Tables(0)

GridView2.DataSource = dset.Tables(1)


Posted by: Vuyiswamb on: 9/5/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

First your Query is not Right , use a Join to Join the Tables and Bind the respective field in the griview

Thank you for posting at Dotnetfunda

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 9/5/2011 [Member] Starter | Points: 25

Hi Vuyiswa,
The query is correct.
I used to get multiple result-set using dataset (reference: http://www.dotnetfunda.com/articles/article1564-how-to-work-with-multiple-results-set-using-dataset-.aspx)

I am getting two tables tblcustomer and tblorder in gridview1 and gridview2
Actually that's not my question:

I am expecting like to store all records in dataset/datatable
and close the connection. after that i like to search records in dataset/datatable to get required result and display the same.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response