Home All Groups Group Topic Archive Search About

OdbcCommand, MySql and auto-increment field

Author
13 Nov 2005 1:05 PM
Ben Fidge
Hi

I have a scenario where i'm writing to a MySql table using OdbcCommand and
the table has an auto-increment field that needs returning after the
"insert" statement executes.

How do I do this?

I've tried creating am Output parameter but that doesn't get populated after
the call to OdbcCommand.ExecuteNonQuery(). This may be because in my
"insert" statemement I'm using "?" to denote parameters as opposed to using
proper named parameters. I also can't seem to get these to work corretly
either.

Any help gratefully received,

Ben

Author
14 Nov 2005 2:55 PM
S.M. Altaf [MVP]
Is it a relatively new version of MySQL?  If yes, then you can use SELECT
@@IDENTITY to get the latest id field's value.

HTH
ALTAF
--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com


Show quote
"Ben Fidge" <ben.fidge@nospambtopenworld.com> wrote in message
news:O5XooLF6FHA.2676@TK2MSFTNGP15.phx.gbl...
> Hi
>
> I have a scenario where i'm writing to a MySql table using OdbcCommand and
> the table has an auto-increment field that needs returning after the
> "insert" statement executes.
>
> How do I do this?
>
> I've tried creating am Output parameter but that doesn't get populated
> after the call to OdbcCommand.ExecuteNonQuery(). This may be because in my
> "insert" statemement I'm using "?" to denote parameters as opposed to
> using proper named parameters. I also can't seem to get these to work
> corretly either.
>
> Any help gratefully received,
>
> Ben
>
>

AddThis Social Bookmark Button