You can merge tables in this way, even if they do not have the same schema
structure.  I have done this when the data is scattered across multiple
tables and the join would have been painful.  There are a couple of things
to keep in mind:

1.  Merge is going to match up the table by table name.  Since the data
tables will come in as "Table", "Table1", and so on, you will need to rename
each of these input tables, in turn to match your target table.  You should
capture each input table name in a temp variable, rename the table, do the
merge, and then restore the table name.  Otherwise you will create a
situation in which there are two or more data tables with the same name, a
VERY BAD THING.

2.  Merge will merge columns into a single row, if the key is set.  If there
is no key specified, merge will just add the rows to the data table.

From: adonis <[EMAIL PROTECTED]>
Reply-To: "Moderated discussion of advanced .NET topics."
<[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Merging Tables in a Dataset
Date: Wed, 30 Jul 2003 12:25:38 -0400

I have created a stored procedure in Sql Server which uses a cursor and
returns multiple identical(schemawise) resultset. When this stored
procedure is used to populate a dataset, naturally multiple datatables are
created. I need to merge the data avaiable in these multiple tables of the
dataset in one table so that I can display the entire data at once in a
datagrid.
Following the code snippet which I am using to merge though in vain.

DataSet dsSummary1 = new DataSet();
DataSet dsSummary;
DataView dvSummary;
dsSummary = BRErrors.GetSummary();
for(int i=0;i <= dsSummary.Tables.Count -1;i++)
{
 dsSummary1.Merge(dsSummary.Tables[i]);
}

dvSummary = dsSummary1.Tables[0].DefaultView;

datagridSummary.DataSource = dvSummary;
datagridSummary.DataBind();

Would appreciate a quick response.

Thank you for your time.

_________________________________________________________________ STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail

Reply via email to