Can not add rows into dataset using Merge()

M

muntyanu

Hi all,

I have problem when merging existing DataTable into new dataset.
DataSet ds = new DataSet();
while ( done )
{
// fill myCustomDataSet.MyTable with data
ds.Merge( myCustomDataSet.MyTable, bPreserveChanges,
MissingSchemaAction.Add );
ds.AcceptChanges(); // tried with and without this line
}
In the loop I am filling my datatable and then I need to add all
content to new dataset.
I tried all combinations for bPreserveChanges, MissingSchemaAction but
can not accumulate rows in new dataset. If bPreserveChanges = true I
have only rows which were added during first call to Merger. If
bPreserveChanges = false I have rows from the last call to Merge.
Tried also to have myCustomDataSet.MyTable with or without primary
key. No difference.

I would really appreciate any suggestions

Thank you , Roman
 
G

Guest

Roman,
It "looks like" from the code you posted that you may be attempting to use
the Merge method to add a table to a target DataSet. What merge is really
designed to do is where each DataSet initially contains a single DataTable
with the same name. After you call the Merge method on the main DataSet and
supply the second DataSet, the main DataSet will contain all its original
columns plus those from the second DataSet. The main DataSet will also
contain the rows from the second DataSet.

Hope that helps,
Peter
 
M

muntyanu

Peter, thank you for response
I think namespaces involved in this issue. My table in custom dataset
depends on complex types which are in separate xsd files. When I
created simple example with no dependencies to namespaces I can
accumulate rows in new dataset. But this is not a case in my real
application. This is my test app that works
private void button1_Click(object sender, System.EventArgs e)
{
Source source = new Source();
Source.Table1Row row = source.Table1.NewTable1Row();
row.ID = "1";
row.f1 = "string for f1 (first time)";
row.f2 = "string for f2 (first time)";
source.Table1.AddTable1Row(row);
// Merge to target
m_TargetDataSet.Merge(source.Table1);
m_TargetDataSet.WriteXml(@"c:\First_Merge.xml");

}

private void button2_Click(object sender, System.EventArgs e)
{
Source source = new Source();
Source.Table1Row row = source.Table1.NewTable1Row();
row.ID = "1";
row.f1 = "string for f1 (second time)";
row.f2 = "string for f2 (second time)";
source.Table1.AddTable1Row(row);
// Merge to target
m_TargetDataSet.Merge(source.Table1);

m_TargetDataSet.WriteXml(@"c:\Second_Merge.xml");
}
I will try to set namespaces properly

Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top