|
-
Apr 26th, 2013, 12:26 PM
#1
Thread Starter
Addicted Member
Quick Question - how would you do this?
I'm creating an access inventory database, one product can have many serial numbers e.g. 10 laptops same model, different serial numbers
I have 2 tables:
1. Products (Columns=ProductID...)
2. SerialNumbers (Columns=ProductID, Serial)
So the SerialNumber table will be related to the Products table by the ProductID
I have 1 form, how can i save product data to the product table and the serial numbers to the serial table, whilst linking the 2 through the ProductID?
I was thinking of using the following however i need the ProductID which i wont have until the product has been added
Code:
'Save to the ProductsTable
Try
Dim sql1 As String
sql1 = "INSERT INTO Products (SKU, Brand, ProductName, Category, SubCategory, DateAdded, Condition, Warranty, Barcode, PurchasePrice, RetailPrice, Taxable, Location, LocationBinRack, Variation, Colour, Specification, Compatability, Includes, Length, Width, Height, WeightG, WeightOz, WeightLb, WeightKg) VALUES ('" & SKUTextBox.Text & "','" & BrandTextBox.Text & "','" & NameTextBox.Text & "','" & CategoryComboBox.Text & "','" & SubCategoryComboBox.Text & "','" & DateTimePicker1.Text & "','" & ConditionComboBox.Text & "','" & WarrantyTextBox.Text & "','" & BarcodeTextBox.Text & "','" & PurchasePriceTextBox.Text & "','" & RetailPriceTextBox.Text & "','" & TaxableComboBox.Text & "','" & LocationTextBox.Text & "','" & LocationBinRackTextBox.Text & "','" & VariationTextBox.Text & "','" & ColourTextBox.Text & "','" & SpecificationTextBox.Text & "','" & CompatabilityTextBox.Text & "','" & IncludesTextBox.Text & "','" & LengthTextBox.Text & "','" & WidthTextBox.Text & "','" & HeightTextBox.Text & "','" & GramTextBox.Text & "','" & OzTextBox.Text & "','" & LbTextBox.Text & "','" & KgTextBox.Text & "') "
Dim adapter As New OleDbDataAdapter(sql1, con1)
Dim dt As New DataTable("Products")
adapter.Fill(dt)
adapter.Update(dt)
con1.Close()
'Save the Serial Numbers to the SerialNumbers table
Dim sql2 As String
sql2 = "INSERT INTO SerialNumbers (ProductID, Serial) VALUES ('" & ProductIDTextBox.Text & "','" & SerialTextBox.Text & "') "
Dim adapter2 As New OleDbDataAdapter(sql2, con1)
Dim dt2 As New DataTable("SerialNumbers")
adapter.Fill(dt2)
adapter.Update(dt2)
con1.Close()
Me.Refresh()
Me.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|