Agree with Leon. DataTable.Merge would work best for your case. You
need to set the MissingSchemaAction enumeration to "AddWithKey" so
that columns in Table 2 get merged along with other existing columns
in Table1. Here is some sample code:

//Merging two DataTables with DataTable.Merge and the
MissingSchemaAction enumeration
            DataTable dtbTable1 = new DataTable("Table1");
            DataTable dtbTable2 = new DataTable("Table2");

            DataColumn dcCol1Tab1 = new DataColumn("Id");
            DataColumn dcCol2Tab1 = new DataColumn("Description");
            DataColumn dcCol3Tab1 = new DataColumn("Value");

            DataColumn dcCol1Tab2 = new DataColumn("Id");
            DataColumn dcCol2Tab2 = new DataColumn("Value");

            dtbTable1.Columns.Add(dcCol1Tab1);
            dtbTable1.Columns.Add(dcCol2Tab1);
            dtbTable1.Columns.Add(dcCol3Tab1);

            dtbTable2.Columns.Add(dcCol1Tab2);
            dtbTable2.Columns.Add(dcCol2Tab2);

            DataRow dr = dtbTable1.NewRow();
            dr["AssetId"] = "1";
            dr["AssetDescription"] = "TVS";
            dr["AssetValue"] = "3000";
            dtbTable1.Rows.Add(dr);

            dr = dtbTable2.NewRow();
            dr["AssetId"] = "2";
            dr["AssetValue"] = "2700";
            dtbTable2.Rows.Add(dr);

            dtbTable1.Merge(dtbTable2, true,
MissingSchemaAction.AddWithKey);


Hope this helps.

Neo


Leon wrote:
> Pantagruel, heya!
>
> Doesn't any of these queries share any columns? Say, Query1 returns
> columns A, B and C, while Query2 returns B, C, D and E? If that's the
> case, the Merge method from a System.Data.DataTable object should do
> the trick.
>
> Hope it helps!
>
> - Leon
>
> On Feb 27, 6:21 am, pantagruel <[email protected]> wrote:
> (...)
> > I need to execute the queries and then loop through the rows of each
> > query and then combine these results, the final combination is written
> > to a text file matching a particular archiving format.
> > The queries do not return the same nunber of columns or rows.
> > If query returns two rows 7 columns, query 2 returns 0 rows but has 4
> > possible columns (if it did return anything), and query 3 returns 3
> > rows 2 columns then the final output should be
> >
> > 3 rows 13 columns with the empty columns in the database replaced by
> > particular characters.
> (...)

Reply via email to