Quote:
quote:Originally posted by Shell84
Sorry to bother you again, but i've been trying to return the id i've just created but it doesn't work and i haven't been able to insert it into my second sqldatasource. i tried creating a max select statement and putting it in a label which i then tried to put into the db but that too was unsuccessful.
|
I've just done something similar that seems to work.
Presuming cmd = new SqlCommand()
Try this as your Insert statement for table one
Code:
cmd.Command = "INSERT INTO Invoices (InvDate, ClientID) VALUES (@InvDate, @ClientID) SELECT SCOPE_IDENTITY()"
add your Parameters and set their values etc then
Code:
dim InvoiceID as Integer
InvoiceID = cmd.ExecuteScaler()
InvoiceID will now hold the Primary Key for the table just written to. You can now change your focus to other tables and utilise this variable for their relationships. I used
Code:
cmd.ExecuteNonQuery()
for these.
Hope this helps