How to merge Rows from different Tables in one Dataset ??

The following code is in C#. Hope this answers your problem
Code:
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=F:\\C#\\Magazine\\Extranet.mdb";

OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
string str = "SELECT * FROM Heading";
OleDbDataAdapter da1 = new OleDbDataAdapter(str, conn);
DataSet ds1 = new DataSet("Heading");
da1.Fill(ds1, "Heading");

DataSet ds2 = new DataSet("SubHead");
str = "SELECT * FROM SubHeading";
OleDbDataAdapter da2 = new OleDbDataAdapter(str, conn);
da2.Fill(ds2, "SubHeading");

DataSet ds3 = new DataSet("Link");
str = "SELECT * FROM Link";

OleDbDataAdapter da3 = new OleDbDataAdapter(str, conn);
da3.Fill(ds3, "Link");
ds1.Merge(ds2);
ds1.Merge(ds3);

dataGrid1.DataSource = ds1.DefaultViewManager;
conn.Close();
 
Back
Top