6

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????

Innova
  • 4,831
  • 21
  • 76
  • 107

4 Answers4

3
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();
bluish
  • 26,356
  • 27
  • 122
  • 180
Rama
  • 31
  • 2
1

You can merge two datatable, here is the sample for that. http://msdn.microsoft.com/en-us/library/system.data.datatable.merge.aspx

Thurein
  • 6,645
  • 5
  • 22
  • 23
0

What you need is a join on the tables before reading them into a DataTable: SQL Joins

Beerdude26
  • 85
  • 10
  • no not using join, wat i need is searching the datas with the cell in gridview. like that.(searching the datas using dynamic queries) – Innova May 24 '10 at 06:21
  • Just noticed that you were looking for the Merge method, which I suggested as a solution first, but then deleted it because I was uncertain what your problem was. You should give the lay-out of the two tables next time :) – Beerdude26 May 24 '10 at 15:07
0

@Ranjana have a look at this MSDN article it deals with what you want..

ACP
  • 34,682
  • 100
  • 231
  • 371