Merge doesn't merge

Y

YBOTI

Perhaps I have the concept all wrong, but based on the documentation and
books I have read it seems this should work. I have multiple complex
datasets in an access db. They have 2 shared primary keys. I have another
dataset that shares one key with them. I need to end up with a single flat
dataset comprised of the merged sets. In a simpler world it would be a
normal sql join, but that is not an option.

Right now, I would love for someone to point out my stupidity and show me
the magic setting I have forgotten. An additional complication is that the
last dataset - the one with just one key was a "relation" issue because that
field in the other table was not unique values. It would be a many-to-one
relation.

I have tried using both the relation AND the merge to no avail. I am not
modifying this data. I just need to read it in, merge it based on the key
values, and kick it out as a single table. As a test I tried creating a more
simple 2 table set (in ms sql), read them into datasets, and tried to merge.
I just do not ever see a merged result. here is the code that goes with a
simple webform with one datagrid.

Dim ds1 As New DataSet()

Dim ds2 As New DataSet()

Dim da1 As New SqlDataAdapter()

Dim da2 As New SqlDataAdapter()

Dim cn As New SqlConnection()

cn.ConnectionString() = "server=daddy;database=test;uid=test;pwd=test"

cn.Open()

da1.SelectCommand = New SqlCommand("select * from table1", cn)

da1.Fill(ds1, "tbl1")

da2.SelectCommand = New SqlCommand("select * from table2", cn)

da2.Fill(ds1, "tbl2")

ds1.Merge(ds2, True, MissingSchemaAction.Add)

DataGrid1.DataSource = ds1

DataGrid1.DataBind()
 
Y

YBOTI

Thank you.

Using the AddWithKey is useful. That will save a step. However, an associate
figured out the missing part that I have not seen documented yet. To
successfully merge multiple tables (including extra new schema from new
tables) you must have the tables in different datasets AND give them the
SAME NAME.

For example, if in MyDataset I have a table named "MyBigFatGreekTable"

MyDataset.Merge(MyOtherDataset, ..., ...)

I must also have a table named "MyBigFatGreekTable" in MyOtherDataset. If
the tables you expect to merge have different names, the merge will not take
place. And, as you point out, you must share primary keys between tables.

Thanks again for the tip.
 

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