Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing



"Michael Slattery" <sncsoftware@xxxxxxxxxxxxxxxx> wrote in message
news:1928F627-97A6-4AC6-B856-FB188ABA464C@xxxxxxxxxxxxxxxx
> How would I use the current data adapter to return a value... I've tried
> adding parameters as Output and ReturnValue (seperate occassions of
> course)
> and all I get back is 0.
>
> "Frank Hickman [MVP]" wrote:
>

I believe that since your creating a new connection the server variable
@@IDENTITY is blank because there has not be any statements executed with
the connection object. You can get the connection object that the adapter
used by using the InsertCommand property of the adapter. From there you can
use the Connection property. Something like this should work for you...

// ta is your Database.dbDataSetTableAdapters.tblPeopleTableAdapter

System.Data.OleDb.OleDbConnection con= ta.InsertCommand.Connection;
OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", con);
int newID = (int)idCMD.ExecuteScalar();

HTH
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.


.