MySQLHelper & LAST_INSERT_ID
Posted by: Shawn Berg
Date: February 17, 2005 09:39PM

I am using the MySQLHelper namespace for data access within my app. I only pass connection strings to the functions, and not actual connections. After executing a command with ExecuteNonQuery I need to make another call to get the LAST_INSERT_ID. I have not tried this yet, but am afraid it will not work due to the fact that a separate connection will be used to query the DB, and it will have no idea of the LAST_INSERT_ID of the previous connection. Even if I did try it and it worked, I'd be leary to it working 100% of the time. Any suggestions how I could make this work after the ExecuteNonQuery?

<code>
Dim CmdText As String, CmdParams(2) As MySqlParameter

'Save email campaign to data store
CmdText = "INSERT INTO tblEmailCampaigns (subject, body, d_t) " & _
"VALUES (?, ?, ?)"

CmdParams(0) = New MySqlParameter("@subject", MySqlDbType.VarChar, 100).Value = _subject
CmdParams(1) = New MySqlParameter("@body", MySqlDbType.VarChar, 999999999).Value = _body
CmdParams(2) = New MySqlParameter("@d_t", MySqlDbType.Datetime).Value = Date.Now

MySqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings("cnTSR1"), CmdText, CmdParams)
</code>

Options: ReplyQuote


Subject
Written By
Posted
MySQLHelper & LAST_INSERT_ID
February 17, 2005 09:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.