Groups | Blog | Home
all groups > dotnet ado.net > september 2005 >

dotnet ado.net : ADO.net 2.0, beta 2, how to get data from 2 tables, not parent-chi


Peter
9/28/2005 6:14:04 AM
in ADO.net 2.0 beta 2
I know how to do the parent-child type.
1. drag a DataGrid control in a window form, get a datasource from
table cust.
2. drag table cust onto the DataGrid.
3. in the data window, right-click the dataset, select configure..
adding table o.
4. drag the child table onto the DataGrid control.
comment: With this way, I build this without a coding. I believe it is
MVC style.
I do not know the steps to join two relational tables into one ADO
table.Please advise. Thanks.
Sahil Malik [MVP]
10/6/2005 12:00:00 AM
If you want a single datatable driven out of two database tables, the best
way to do that is to simply execute a join query on the database.

If you wish to combine two datatables to give you one single datatable, the
best way to do that is to iterate over values of both tables and use the
LoadDataRow method.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------


[quoted text, click to view]

Cor Ligthert [MVP]
10/6/2005 11:06:34 AM
Peter,

If it is a one to one relation you can use the merge.

Be aware that the keys have to be equal and that the collecting table has to
have all columns you need (probably is the best to do two merges in a new
created datatable).

(I don't think that you can do this with drag and drop)

Here a simple sample that can lead you in my opinion to your solution.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=edb1409d-5394-468f-a63f-de3a5d92b14a

I hope this helps,

Cor

AddThis Social Bookmark Button