Simulating Joins With A DataSet.

J

Jeff Zuerlein

I have been trying to write a function that can take in
two datatables (Source, Destination), and add a column
from the source table to the destination table.

Example:
ds.Relations.Add("CustomerOrders", _
ds.Tables("Customers").Columns("CustomerID"), _
ds.Tables("Orders").Columns("CustomerID"))
ds.Tables("Orders").Columns.Add("CompanyName", GetType
(String), _
"Parent(CustomersOrders).CompanyName")

It works fine as long as all the tables are in the same
dataset. I would like for the Source and Destination
tables to be able to come from different datasets. When I
try to use the DataTable.Copy method, to bombs and tells
me "Object reference can't be set to instance of object."
If I don't run the Columns.Add line, the rest of the code
works great. Is there something happening that prevents
the copy method for completing when columns have been
added based on a relationship?

Jeff
 
M

Miha Markic

Hi Jeff,

I guess the expression column is causing you problems.
You might remove it before doing copy and re-add it after.
 
G

Guest

Thanks for the response.

I tried to remove all the relation objects before doing
the copy, but it didn't help. I tried to remove the
destination table from the dataset as well, and it didn't
work.

The goal was to get a copy of the new destination table
that was not part of the dataset, so I can't really remove
it before the copy.
 
M

Miha Markic

Hi,

I was talking about the column you explicitely added and it is normally
reffered as "expression columns" since it doesn't contain real data.
 

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