Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 table,s1 and s2

s1 field ----NO,NAME
s2 field-----NO,CITY,country
I NEED NO,NAME,CITY,country IN GRIDVIEW

below code does not work fatch data from 2 table in gridview

VB
Private Sub binddata()
cn = New SqlConnection("Data Source=abc-64B13238\SQLEXPRESS;Initial Catalog=std;Integrated Security=True")
        adp = New SqlDataAdapter("select * from s1", cn)
        adp.Fill(ds, "no")
        adp = New SqlDataAdapter("select * from s2", cn)
        adp.Fill(ds1, "no")
        ds.Merge(ds1)
        DataGridView1.DataSource = ds
End sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Binddata()
End sub
Posted

Isn't this the same as this[^] that you asked few days back?

BTW, looks like your two tables are totally independent.
Why don't you try something like :
SQL
SELECT * FROM s1, s2 

and put the data in a table to use it?

Is NO a common column? If so then:
SQL
SELECT s1.NO, s2.CITY, s2.COUNTRY, s1.NAME  FROM s1 INNER JOIN ON s1.NO = s2.NO


No need to have two dataset and do a merge anywhere. Single query returns the data you need.
 
Share this answer
 
If Both tables can have one to one relationship, create a foreign key field in one of the table. Execute a join query and use the result to bind the gridview.

Other wise how you can match one row from a table to other row in other table. Gridview need to get artificial intelligence then
 
Share this answer
 
hi,

One possible suggestion:
1. You may create a DataTable dt3 to merge table1 and table2. Then bind dt3 to gridview.
2. After update data, compare your dt3 to table1. Save the changes to table1.
3. Update table1 to database.
This may be a way for your problem.
I hope this can help resolve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900