Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This the last thing I did
C#
con = new SqlConnection(str);
con.Open();
string custom_tb = "select branch_name,name,address,insurance_cost,record_date  from customers,branches where branches.code_branch=customers.code_branch ";
string branches_tb = "select * from branches";
string type_tb="select * from insurance_type";
dset = new DataSet();
da = new SqlDataAdapter(custom_tb , con);
da.Fill(dset, "customers");
da = new SqlDataAdapter(custom_tb, con);
da.Fill(dset, "branches");
da = new SqlDataAdapter(type_tb, con);
da.Fill(dset, "insurance_type");
builder = new SqlCommandBuilder(da);
dset.Relations.Add ("branches_customers",dset.Tables ["branches"].Columns ["code_branch"],
dset.Tables ["customers"].Columns ["code_branch"]);

dset .Relations .Add ("insurance_type_customers",dset .Tables ["insurance_type"].Columns ["code_type"],
dset .Tables ["customers"].Columns ["code_type"]);
dataGridView1.DataSource = dset.Tables["customers"];
Posted
Updated 28-Nov-11 4:21am
v3
Comments
Addy Tas 28-Nov-11 18:08pm    
Could you rephrase the question? Also make clear what exectly is not working. Does it not display correctly or do you get an exception of any kind?

Cheers, AT
mhassan083 2-Dec-11 9:39am    
I want Two table data to be shown in One Gridview.

1 solution

Corrections

C#
da = new SqlDataAdapter(custom_tb, con);//branches_tb 
           da.Fill(dset, "branches");



if u want Two table data to be shown in One Gridview.

Try to Join the Table and Retreive the Columns as per your needs.

Simply then add the datatable to the datasource of the gridview and you would see the desire result.


Hope what i said is to your expectation.


Thanks
 
Share this answer
 
Comments
mhassan083 2-Dec-11 9:45am    
how i can join tables
suhailnoorpawane 6-Dec-11 0:18am    
If ur using stored prodecure do it through that
let me know the two table and the columns it has

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