how to join two datatable datas into one datatable to show in one gridview
i.e in 1 datatable i have username and pwd and in another datatable i have that user details. how to show all these in one datatable to get those values display in gridview(asp.net)
any idea????
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
on=new SqlConnection("Data Source=MCN101; Initial Catalog=MergeTable; Uid=sa; pwd=");
da = new SqlDataAdapter("Select * from Table1", con);
da.Fill(ds1, "Record");
da = new SqlDataAdapter("select * from Table2", con);
da.Fill(ds2, "Record");
ds1.Merge(ds2);
GridAllRecord.DataSource = ds1;
GridAllRecord.DataBind();
Method 2
You can merge two datatable, here is the sample for that.
http://msdn.microsoft.com/en-us/library/system.data.datatable.merge.aspx
Method 3
What you need is a join on the tables before reading them into a DataTable: SQL Joins
Method 4
@Ranjana have a look at this MSDN article it deals with what you want..
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0