Creating relationships for access database with linked tables

Matt_h

Member
Joined
Apr 12, 2007
Messages
17
Programming Experience
Beginner
I am trying to create relationships for a lot of linked, mysql tables, via vb.net using ADOx.net, I am using the following code (modified just to work on two tables):


Code:
VB.NET:
dim cat as adox.catalog
dim tbl as adox.table
dim fk as adox.key
dim cn as adodb.connection
dim dir_nme as string = "c:\db\"
dim mdb_name as string = "test.mdb"

cn.open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dir_name & mdb_name)
cat.activeconnection = cn

tbl = cat.tables("Orders")

fk.name = "fk1"
fk.type = keytypeenum.adkeyforeign

fk.relatedtable = "Customers"

fk.columns.append("Customers_PKEY")

fk.columns("Customers_PKEY").related column = "PKEY"

fk.type = keytypeEnum.adkeyforeign

tbl.keys.append(fk)
Now if I run the above code on the related tables I get the error message:

"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Access_Creator.exe

Additional Information: Unspecified Error"

Creating the relationships manually I receive no error, creates a one to many relationship.

If I save the same tables to the Access database and run the code, the code works fine and creates the relationships, creates a one to many relationship with enfored referntial integrity.

I am assuming that the linked tables won't allow relationships to be made with enforced referntial integrity, from doing a search when using linked tables integrity is maintained at source anyway, so my question is how to create the relationships withoput enforcing referential integrity or is the error from something else that I am missing?

regards,

Matt
 
Back
Top