Data Relation Problem

liam

Member
Joined
Jun 8, 2004
Messages
23
Programming Experience
Beginner
I'm currently stucked in one of my apps. I hope someone could help me. I've searched some books already but just couldn't find the right solution.

I have 4 tables in MS ACCESS
They are all related to on PROVIDER ID

However when I relate two tables, I receive the message that the OBJECT REFERENCE NOT SET TO AN OBJECT.

Here's the code I use
Dim AcConRel As DataRelation = dsMAIN.Relations.Add("AcCon", dsMAIN.Tables("infoACCOUNT").Columns("AcRefNo"), dsMAIN.Tables("infoACCOUNTcontact").Columns("AcRefNo"))


 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
give this a try:

VB.NET:
   [color=black]Dim AcConRel As DataRelation
   [/color][color=black]AcConRel = New DataRelation("AcCon", dsMAIN.Tables("infoACCOUNT").Columns("AcRefNo"), dsMAIN.Tables("infoACCOUNTcontact").Columns("AcRefNo"))
    dsMAIN.Relations.Add

A few more lines, but I think you'll find it works.
[/color]
 
Last edited:

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
Opps I meant

I forgot that you must send the DataRelation that you want to add as an argument in the last step.

VB.NET:
 	   ' Declare a DataRelation
 		Dim CustomersOrdersRel As DataRelation
 
 		' Assign the relation
 		CustomersOrdersRel = New DataRelation("CustomersOrders", newDS.Tables("Customers").Columns("CustomerID"), newDS.Tables("Orders").Columns("CustomerID"))
 
 		' Add the relationships
 		newDS.Relations.Add(CustomersOrdersRel)
 
Top Bottom