ADO.NET Joins

M

Micky Doyle

Hi,

Is there a method to combine two ADO.NET DataTables by applying a
DataRelation, as if making an SQL join, to produce a single object? I
would like to pass the product of this "join" to an ASP.NET DataGrid
and ideally would like to be able to edit the data and have the
changes reflected in the original DataTables.
I think this might be stretching it a bit thought :)


Thanks, Micky.
 
H

Hussein Abuthuraya[MSFT]

Micky,

No, the Data relation is not for this purpose. It is to setup a relationship between 2 tables (parent-child or master-detail style) so that you can navigate from a parent row to its
related child rows as well as do cascade updates or deletes.

Now your question has 2 parts: a) display data in a Datagrid and b) Update the data.

For the first part, it is easy to setup if you write the Select query of the DataAdapter ready to join the 2 tables in mind. Upon filling the DataSet from that dataAdapter, it will bring
all the joined data and put it in one datatable. Now set the Datasource property of the datagrid to that table will accomplish this task.

Now for the second part about the Data Update, you are on your own where you must write yourself the Update command for each table separate and execute it. This
requires good knowledge of SQL Syntax and assigning the proper parameters or build the Update command by concatenating all the parameter values in the string. If you
pick an advanced book on ADO.NET (such as Core ADO.NET by David Sceppa) he would have detailed sample on how to do that.

I hope this helps.


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
 
M

Micky Doyle

Hi Hussein,

Thanks for your reply. My solution to this problem is copying the
data, field by field, from the two DataSets into a third (One of the
source DataSets is populated manually, not from the database - so i
can't do an SQL join.) I then pass this into the DataGrid for
representation in the UI. At the DataGrid's update command i then have
to update two DataSets. I was hoping there would be a better way but
it appear there isn't.

Thanks,
Micky.
 

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