I have a function i use in Windows forms applications for returning the primary key of an auto incrementing identifier. Im making an ASP application...and i want this to be as quick as possible.
Whats the quickest way to return the number of the primary key ,of a record that was just inserted into a database?
Here is an example of a function i used in a windows form app. But a completely different context. Since i dont need to store them.
Whats the quickest way to return the number of the primary key ,of a record that was just inserted into a database?
Here is an example of a function i used in a windows form app. But a completely different context. Since i dont need to store them.
Code:
returns customerIDs
Private Function getCustomerID(ByVal strFirstName As String, ByVal strLastName As String, ByVal dtDate As Date) As Integer
Dim strSQL As String = "SELECT FirstName, LastName, CustomerID, LastUpdate FROM tblCustomer WHERE LastUpdate = " _
& "#" & dtDate & "#" & " AND FirstName = " & "" & strFirstName & "" _
& " AND LastName = " & "" & strLastName & ""
Static intIncrementID As Int32
auto increment the temporary holding area of customerIDs
intIncrementID += 1
dsCustomers.Tables.Add("CustomerID" & intIncrementID)
daCustomerID = New OleDb.OleDbDataAdapter(strSQL, cnCustomers)
daCustomerID.Fill(dsCustomers.Tables("CustomerID" & intIncrementID))
Return dsCustomers.Tables("CustomerID" & intIncrementID).Rows(0).Item("CustomerID")
End Function
Last edited by a moderator: