DataSet Merge?

J

Joey Lee

Hi,

I am confused as what the DataSet Merge() function does.

Currently I have two datatable which was selected from different table in
mssql.

Now with both different datatable. there are unique keys which determine the
the relationship.

Ex

Table 1 Name - Employer
Fields - id, name, age
Values -
1, Joe, 80
2, Bob, 23
3, Fred, 40

Table 2 Name - Car
Fields - id, car, price
Values -
1, Ferrari, 1.0
2, Volvo, 0.8

Now, by using id as the relationship, doing a merge I would like to get

New Table
Values - id, name, age, id, car, price
1, Joe, 80, Ferrari, 1.0
2, Bob, 23, Volvo, 0.8
3, Fred, 40 , null, null

Is this possible? How do I go about doing this? Please note I cannot use a
join sql statement, as the values selected out has already been processed by
different complex business logic.

I have followed the example on this site
http://weblogs.sqlteam.com/davidm/archive/2004/01/20/748.aspx, which gives
me the result that i want(after tweaking it). However this requires looping
and extra coding to merge them up by parsing the rows of both table. Is
there a function in DataSet to do something like the above example?

Thanks

Joey
 
M

Manohar Kamath

There is nothing inherent in the DataSet that would let you do that. You
have to create a DataTable outside of the data set, and add it to the
dataset when you are done filling the values. Something like:

DataTable myTable = new DataTable();
DataTable.TableName = "MyTable";

// Create columns, and add data here
....
....

// Add the table to the DataSet
myDataSet.Add(myTable);

Note: If you did not have the complex business logic requirement, you could
just create a DataView that joins the existing tables in the set.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top