maintaining relationships at runtime

  • Thread starter Thread starter gaffar
  • Start date Start date
G

gaffar

Hello Sir,

I have created database(ms access) and tables at runtime how to maintain
relation ships between the tables. by using vb.net.

Thanking u sir.
 
gaffar said:
I have created database(ms access) and tables at runtime how to maintain
relation ships between the tables. by using vb.net.

Create DataRelation objects that connect one or more DataColumn(s) from the
parent table to one or more DataColumn(s) from the child table. Then Add the
DataRelations to the DataSet that you've filled with schema and data from your
Access database.

Dim relation As DataRelation
relation = New DataRelation( "Customers_Orders", _
dataSet1.Tables("Customers").Columns("CustomerID"), _
dataSet1.Tables("Orders").Columns("CustomerID"), True)
dataSet1.Relations.Add( relation)

In this case, I just happened to use the DataRelation constructor that takes two
single-column references in the parent (Customers) and child (Orders) tables;
if the relationship were a multi-column one you would use one of the overloads
that accepts arrays of DataColumns (both arrays must have the same number
of columns).

Additionally, notice the True argument. Overloads of the DataRelation constructor
that take this last boolean parameter with add Constraints to the ConstraintsCollection
for cascading deletions, etc. If your Access data model was created with these con-
straints and you want them instituted within ADO.NET, then you want to pass True
for this parameter.


Derek Harmon
 
I see that Sahil and Derek already answered this - but I will add that if
you use Typed Datasets, you can visually build those DataRelations and get
all of the benefits of Typed DataSets.
 
Back
Top