johnqtr
asked on
Insert Into
I'll try to explain this the best I can. I have a table named "Batches" that I'm trying to insert into one row of data at a time. In VB.NET I have a dropdown box that displays a number from another column "Code" from another table "Products". Inside the "Products" table is a column named "ProductID" which corresponds with the Products.Code column. Here is an example:
Products Table
ProductID Code
1 301C
2 3386
3 3278
4 3375
5 3201
I am trying to insert the ProductID number into "Batches.Product" column.
In VB.NET my dropdownbox is called "product" and displays the Code from "Products.Code". My question is, how do I insert into Batches.Product the "ProductID" corresponding with the "Code".
This is what I have so far, but I know it's incomplete:
INSERT INTO Batches (Product)
Values ('" & product.selectedItem.Text & "')"
Products Table
ProductID Code
1 301C
2 3386
3 3278
4 3375
5 3201
I am trying to insert the ProductID number into "Batches.Product" column.
In VB.NET my dropdownbox is called "product" and displays the Code from "Products.Code". My question is, how do I insert into Batches.Product the "ProductID" corresponding with the "Code".
This is what I have so far, but I know it's incomplete:
INSERT INTO Batches (Product)
Values ('" & product.selectedItem.Text & "')"
ASKER
Okay, what about if I needed to enter data in more than one column? Let's say I need to enter 25863 in the "BatchID" column within table "Batches"? Would I do this?
"INSERT INTO Batches (Product, BatchID)
VALUES ('', '25863')
SELECT ProductID
FROM Products
WHERE Code = '" & product.selectedItem.Text & "'"
"INSERT INTO Batches (Product, BatchID)
VALUES ('', '25863')
SELECT ProductID
FROM Products
WHERE Code = '" & product.selectedItem.Text & "'"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You! That worked great!
insert into batches
(productid
,product
,batchid
)
select
productid,
code,
batchid = 25863
from products
(productid
,product
,batchid
)
select
productid,
code,
batchid = 25863
from products
"INSERT INTO Batches (Product)
SELECT ProductID
FROM Products
WHERE Code = '" & product.selectedItem.Text & "'"