When I insert, I do something like this:
INSERT INTO table (col1,col2) VALUES (data1,data2);SELECT LAST_INSERT_ID()
and just run the query as I received the data. In VB.NET syntax (if you have a file MySql.Data.MySqlClient.dll):
Dim sql As String = "[sql string above]"
Dim dr As MySqlDataReader = YourRetrieveDataFunction(sql)
dr.Read()
yourObjectInstance.ID = dr(0)
dr.Close
These are technically two queries, but only one hit in the database :)
Jason source
share