3 messages in com.mysql.lists.dotnetRe: Acquiring Automatically Increment...
FromSent OnAttachments
Chris Ortmann24 Mar 2006 08:17 
Ben Reichelt24 Mar 2006 08:19 
Emanuel Oliveira24 Mar 2006 08:42 
Subject:Re: Acquiring Automatically Incremented Value
From:Emanuel Oliveira (eman@gmail.com)
Date:03/24/2006 08:42:40 AM
List:com.mysql.lists.dotnet

Hi Chris,

- Imagining that the auto-increment column is named «id», then one way to do what you need is to execute the following sql: - SELECT max(id) FROM myTable; - So by using the very friendly mySqlHelper static class, you can achieve what you need in just two lines of code: -

Dim myDataSet As System.Data.DataSet = * MySqlHelper.ExecuteDataset*("Data Source=localhost;Database=myDB;User ID=xxxxxxx;Password=xxxxxx", "SELECT max(id) myLastID FROM news_db n;")

Dim myLastInsertedID As Integer = myDataSet.Tables(0).Rows(0)( "myLastID") -

If you are not familiar with the *mySqlHelper* static class, well, in the several easy methods it contains, the one I mostly use for 99% of all my sql needs (select,insert,update,..), is the ExecuteDataset, which does all the house-cleaning for you: -

automatically creates connection and connects -

executes whatever sql you passed in -

close connection -

returns a simples Dataset with in-memory snapshot of the returned data - instead of using a reader which by my experience trows lot's of connection errors, and other intermitent errors. With the mySqlHelper, I'm getting 100% success in all Calls. This great class just KILLED *not the radio start* :) but all sort of intermitent error's with using .NET connector. [Connector 1.0.7 + DB4.1.9). -

Also, to get *number of returned rows*: -

dim numRows= myDataSet.Tables(0).Rows.Count -

And so on.. :)

On 3/24/06, Chris Ortmann <ort@gmail.com> wrote:

I posed this question on the .Net Connector forums but unfortunately never got a response.

Upon an insert into a table that uses an auto increment column as the primary key, is there a neat way to acquire the newly created ID with the ConnectorNet library, as there is using PHP?

Thanks,