|
| Insert data to two related tables in access |
 |
Thu, 20 Mar 2008 16:15:23 +000 |
Hi,
I have created a database in access and a website in asp.net
what i want to do is to insert data into 2 or more related tables such as
customer and customer order.
I know how to insert data to one table ( code below), but problem is adding to
two related tables.
Can anyone help please :(
Thank you a million in advance
code to add data to one table in access:
Imports System.Data.OleDb ..........etc
Public strConn AsString = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=
" & Server.MapPath("Customer.mdb")
ProtectedSub submit1_Click(ByVal sender AsObject, ByVal e As System.EventArgs)
Handles submit1.Click Dim cmd AsNew OleDbCommand("INSERT INTO
Customer(Name,EMailAddress)VALUES('" & name.Text & "','"
& email.Text"')", New OleDbConnection(strConn))
cmd.Connection.Open() cmd.ExecuteNonQuery() cmd.Connection.Close()
EndSub
|
| Post Reply
|
| Re: Insert data to two related tables in access |
 |
Thu, 20 Mar 2008 20:00:17 +000 |
If you are first creating a customer record, then an order for that customer,
you need to fire three consecutive commands. The first one will add the
customer, the second one will get their newly created ID, then the third one
will add a new order, and include the ID of the new customer.
http://www.mikesdotnetting.com/Article.aspx?ArticleID=54
|
| Post Reply
|
|
|
|
|
|
|
|
|
|