Is there a built in mechanism for representing a Joined View?  
Author Message
XBTester





PostPosted: .NET Framework Data Access and Storage, Is there a built in mechanism for representing a Joined View? Top

A DataView represents a single table. I can create a view in SQL Server that joins two tables and then read/fill a DataTable with that SQL View. I can bind this DataTable into a DataGridView. I can also read each of the tables into seperate in memory DataTables. If I add a record to the child DataTable and update the SQL table, then re-read the View from SQL the DataGridView will be updated with the new joined Row(s). This requires a roundtrip to SQL Server. I have not found a way to represent the joined tables in memory that would allow me to update one of the tables and have DataGridView be updated without a round trip to SQL Server. I am sure I could write custom code to do it, but if there is an existing mechanism I would prefer to use it.

Ben




.NET Development1  
 
 
Paul Domag





PostPosted: .NET Framework Data Access and Storage, Is there a built in mechanism for representing a Joined View? Top

Hi,

I guess what you would want is the ability to JOIN two datatables. If so, I'm not quite sure if this is available currently in ADO.Net but I've seen this feature on the upcomming LINQ Project. See it here:

http://www.microsoft.com/belux/msdn/nl/community/columns/himschoot/linq.mspx

There is a sample there that joins 2 collections based on a query, very similar to INNER JOINS in sql. Since DataTables are also collections then you can now create a view-type datatable...

cheers,

Paul June A. Domag



 
 
MihaiBejenariu





PostPosted: .NET Framework Data Access and Storage, Is there a built in mechanism for representing a Joined View? Top

DataView in ADO.NET is different from View in SQL Server. Generaly, you use a DataView when you want to sort/filter a DataTable and this is not your case.

You can load both table in a single dataset (which will have 2 datatables) and then define a relationship between them.

ds.Relations.Add(
"Category ",
ds.Tables("Categories").Columns("CategoryID"), _
ds.Tables("Products").Columns("CategoryID"))

More details here:
http://www.dotnetjohn.com/articles.aspx articleid=63



 
 
oblax77





PostPosted: .NET Framework Data Access and Storage, Is there a built in mechanism for representing a Joined View? Top

Hi,
You can use the "Merge" funtion of DataTable to merge 2 datatables.
For example:
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
//lets assume that these 2 datatables have data.
//merge these datatables
dt1.Merge(dt2);//use other overloads if you need them.

hth,
Michael Castillones