Quote
You do not need to use SP in this case. All you need to do is to execute
SELECT SCOPE_IDENTITY() statement right after you inserted record. Main rule
is to execute it against same connection which application uses to insert
record, otherwise you will not get proper value
SELECT SCOPE_IDENTITY() statement right after you inserted record. Main rule
is to execute it against same connection which application uses to insert
record, otherwise you will not get proper value
But since Insert is an ExecuteNonQuery and Select is not, I'm a bit confused on how to make this work with my code... Code to follow...
Public Sub InsertMyData(ByVal myConnString As String, _ ByVal customer_bus_name As String, _ ByVal customer_address As String, _ ByVal customer_city As String, _ ByVal customer_state As String, _ ByVal customer_zip As String, _ ByVal customer_taxid As String, _ ByVal customer_discount_rate As String) Dim myInsertQuery As String = "INSERT INTO customers VALUES( '" & customer_bus_name & "', '" & customer_address & "', '" & _ customer_city & "', '" & customer_state & "', '" & customer_zip & "', '" & customer_taxid & "', '" & customer_discount_rate & "' )" Dim myConnection As New SqlConnection(myConnString) Dim myCommand As New SqlCommand(myInsertQuery, myConnection) Dim retvalue As Integer myConnection.Open() retvalue = myCommand.ExecuteNonQuery() myConnection.Close() End Sub