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. Database & SysAdmin
  3. Database
  4. Access SQL INSERT

Access SQL INSERT

Scheduled Pinned Locked Moved Database
helpdatabasetutorialquestion
3 Posts 2 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.
  • B Offline
    B Offline
    braveheartkenya
    wrote on last edited by
    #1

    I'm new to SQL, so forgive my ignorance. I have a number of related tables. Of these there are 3 which are of concern to my problem: Invoices, InvoiceItems and Products. There is a 1:M r/ship between Invoices as well as between Products and Invoice items. The Invoice items table has InvoiceItemID, InvoiceID, ProductID, Quantity and Price. I would like to add 3 InvoiceItems as records in my InvoiceItems table and i would like to have them related to one Invoice (the last Invoice in my case) in the invoices table, that is, also the field in the InvoiceItems called InvoiceID for these 3 records should have the same InvoiceID. All the Primary Keys are set to AutoNumber. These are the the statements i used: INSERT INTO InvoiceItems ( InvoiceID, ProductID, Quantity, Price ) VALUES (4, 8, 1, 0); INSERT INTO InvoiceItems ( InvoiceID, ProductID, Quantity, Price ) VALUES (4, 9, 4, 0); INSERT INTO InvoiceItems ( InvoiceID, ProductID, Quantity, Price ) VALUES (4, 10, 2, 0); I would like to do this using some sort of INSERT SQL statements, but it's just not working. I can INSERT one InvoiceItem, but when i try to INSERT the next one i get some long error saying something about "type conversion failure","key violations", "lock violations" and "validation rule violations" Does anyone know why this is happening and how to correct it? Any help would be much appreciated.

    M 1 Reply Last reply
    0
    • B braveheartkenya

      I'm new to SQL, so forgive my ignorance. I have a number of related tables. Of these there are 3 which are of concern to my problem: Invoices, InvoiceItems and Products. There is a 1:M r/ship between Invoices as well as between Products and Invoice items. The Invoice items table has InvoiceItemID, InvoiceID, ProductID, Quantity and Price. I would like to add 3 InvoiceItems as records in my InvoiceItems table and i would like to have them related to one Invoice (the last Invoice in my case) in the invoices table, that is, also the field in the InvoiceItems called InvoiceID for these 3 records should have the same InvoiceID. All the Primary Keys are set to AutoNumber. These are the the statements i used: INSERT INTO InvoiceItems ( InvoiceID, ProductID, Quantity, Price ) VALUES (4, 8, 1, 0); INSERT INTO InvoiceItems ( InvoiceID, ProductID, Quantity, Price ) VALUES (4, 9, 4, 0); INSERT INTO InvoiceItems ( InvoiceID, ProductID, Quantity, Price ) VALUES (4, 10, 2, 0); I would like to do this using some sort of INSERT SQL statements, but it's just not working. I can INSERT one InvoiceItem, but when i try to INSERT the next one i get some long error saying something about "type conversion failure","key violations", "lock violations" and "validation rule violations" Does anyone know why this is happening and how to correct it? Any help would be much appreciated.

      M Offline
      M Offline
      MuhammadKhanAli
      wrote on last edited by
      #2

      I think you have not entered the master data ProductID Name 8 ABC InvoiceID Invoice Name 4 ZXZ InvoiceID ProductID Qty Price 4 8 1 0 ----> ok 4 9 4 0 ----> ProductID is not existing 4 10 2 0 ----> ProductID is not existing I think ! This is the problem

      B 1 Reply Last reply
      0
      • M MuhammadKhanAli

        I think you have not entered the master data ProductID Name 8 ABC InvoiceID Invoice Name 4 ZXZ InvoiceID ProductID Qty Price 4 8 1 0 ----> ok 4 9 4 0 ----> ProductID is not existing 4 10 2 0 ----> ProductID is not existing I think ! This is the problem

        B Offline
        B Offline
        braveheartkenya
        wrote on last edited by
        #3

        Thanks ... you were right ...i can't believe it was something so small

        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