By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

Can not add rows into dataset using Merge()

P: n/a
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

Dec 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"mu******@hotmail.com" wrote:
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

Dec 13 '05 #2

P: n/a
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

Dec 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.