Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to create relationship of 2 tables using OleDbConnection

How to create relationship of 2 tables using OleDbConnection

Scheduled Pinned Locked Moved Visual Basic
tutorialdatabasehelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gwittlock
    wrote on last edited by
    #1

    I have a MS Access Database that has 2 tables (for this example) Table_1 has a Filed named [ID] which is the Primary Key Table 2 has a field name [tbl1ID] I want to Create a relationship between Table_2 and Table_1 I tried:

    "ALTER TABLE Table_2 ADD CONSTRAINT [tbl1ID] FOREIGN KEY (MyNewID) REFERENCES [Table_1](ID)"

    I get the error "Can Not Find Table Or Constraint" I know Table_1 and Table_2 exists and I know ID is a filed in Table_1 and I know tbl1ID is in Table_2 So can anyone tell me where I went wrong?

    P G 2 Replies Last reply
    0
    • G gwittlock

      I have a MS Access Database that has 2 tables (for this example) Table_1 has a Filed named [ID] which is the Primary Key Table 2 has a field name [tbl1ID] I want to Create a relationship between Table_2 and Table_1 I tried:

      "ALTER TABLE Table_2 ADD CONSTRAINT [tbl1ID] FOREIGN KEY (MyNewID) REFERENCES [Table_1](ID)"

      I get the error "Can Not Find Table Or Constraint" I know Table_1 and Table_2 exists and I know ID is a filed in Table_1 and I know tbl1ID is in Table_2 So can anyone tell me where I went wrong?

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Not sure, but are tbl1ID and MyNewID in the wrong order?

      G 1 Reply Last reply
      0
      • P PIEBALDconsult

        Not sure, but are tbl1ID and MyNewID in the wrong order?

        G Offline
        G Offline
        gwittlock
        wrote on last edited by
        #3

        Well I flip them per your suggestion and I still Get the same error.

        1 Reply Last reply
        0
        • G gwittlock

          I have a MS Access Database that has 2 tables (for this example) Table_1 has a Filed named [ID] which is the Primary Key Table 2 has a field name [tbl1ID] I want to Create a relationship between Table_2 and Table_1 I tried:

          "ALTER TABLE Table_2 ADD CONSTRAINT [tbl1ID] FOREIGN KEY (MyNewID) REFERENCES [Table_1](ID)"

          I get the error "Can Not Find Table Or Constraint" I know Table_1 and Table_2 exists and I know ID is a filed in Table_1 and I know tbl1ID is in Table_2 So can anyone tell me where I went wrong?

          G Offline
          G Offline
          gwittlock
          wrote on last edited by
          #4

          Well It Looks like I had a typo after-all. I had a space in the sable name where it should have been an Underscore. Thanks.

          A 1 Reply Last reply
          0
          • G gwittlock

            Well It Looks like I had a typo after-all. I had a space in the sable name where it should have been an Underscore. Thanks.

            A Offline
            A Offline
            AccessDeveloper
            wrote on last edited by
            #5

            I connect them by using a select query. Access is all about tables, querys and records

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups