getting the value of the primary key on an insert

E

evandela

I am having pretty much of the same problem but with an access
Database. When I insert a new product, I need to update a second
reference table with the primary key of the new insert. I have included
my code below to make it a little clearer... if anyone can offer me any
help here - it would be REALLY appreciated.


Protected Sub addNew_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

AccessDataSource1.InsertCommand = "INSERT INTO product
(productName,productPartNumber,productNSNNumber,productDescription)
VALUES ('New Product','1234567890','1234567890','New Product
Description')"

AccessDataSource1.Insert()

AccessDataSource1.InsertCommand = "INSERT INTO
countryProductCost(countryID,productID,cost) VALUES ('1',' <NEED TO
INSERT THE primary key of the insert performed above here> ','0')"


End Sub
</script>

<asp:Button ID="btnAddProduct" runat="server" Text="Add Product"
OnClick="btnAddProduct_Click" /><br />

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="App_Data\products.mdb" />

Anyone have any ideas, they would be really appreciated.
 
G

Guest

I too would like an answer to this as it is very easy to do in PHP. If you
used SQL Server instead you could set up a trigger to update the secobnd
table when a record was inserted in the first table, but i don't think access
supports triggers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top