CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Creating relationships dynamically

    I have created a program that imports some data to a new Access mdb file from SQL Server. It works well and creates the tables I want, the fields and fills them with the appropriate data. I'am asking now, If I can (through code) to create to this mdb the relationship that I want between two tables for example. Is it possible?

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Creating relationships dynamically

    if you use ADO for accessing your Jet database, you could use ADOX's object model (=ADO Ext. 2.1 for DDL and Security).
    here is a sample from the online docs

    Sub CreateKey()

    Dim kyForeign As New ADOX.Key
    Dim cat As New ADOX.Catalog

    ' Connect the catalog
    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\Program Files\Microsoft Office\" & _
    "Office\Samples\Northwind.mdb;"

    ' Define the foreign key
    kyForeign.Name = "CustOrder"
    kyForeign.Type = adKeyForeign
    kyForeign.RelatedTable = "Customers"
    kyForeign.Columns.Append "CustomerId"
    kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
    kyForeign.UpdateRule = adRICascade

    ' Append the foreign key
    cat.Tables("Orders").Keys.Append kyForeign

    'Delete the Key as this is a demonstration
    cat.Tables("Orders").Keys.Delete kyForeign.Name
    End Sub




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured