Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- From: "Michael Slattery" <sncsoftware@xxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jan 2006 05:32:04 -0800
Of course the line
OleDbConnection = ta.Connection;
should read
OleDbConnection con = ta.Connection;
"Michael Slattery" wrote:
> Frank,
>
> Still no go...
>
> If I try what you asked...
>
> OleDbConnection = ta.Connection;
> OleDbCommand idCMD = new OleDbCommand("SELECT @@IDENTITY", con);
> int newID = (int)idCMD.ExecuteScalar();
>
> I get the following InvalidOperationException
>
> ExecuteScalar requires an open and available Connection. The connection's
> current state is closed.
>
> Of course I can surround the above code with
> con.open();
> con.close();
>
> but were then back to the original error of being on a different connection...
>
>
>
> "Frank Hickman [MVP]" wrote:
>
> > "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.
> >
> >
> >
.
- Follow-Ups:
- Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- From: Kevin Yu [MSFT]
- Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- References:
- Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- From: Frank Hickman [MVP]
- Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- From: Frank Hickman [MVP]
- Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- Prev by Date: Re: Permissions to allow creation of forms etc?
- Next by Date: Re: Newbie : Oracle data to Access table.
- Previous by thread: Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- Next by thread: Re: VS.2005 c# Autonumber via Access with @@IDENTITY Failing
- Index(es):
Relevant Pages
- Re: Router Two NIC Static ISP Setup Problem
... it says to use the "Direct Broadband ... Apparently using the "Router Connection"
... > "Frank McCallister" wrote in message ... >>> The confusion comes
when the wizard starts asking for IP addresses. ... (microsoft.public.windows.server.sbs) - Re: Global Functions
... object-oriented solutions. ... Dim ConnL3Producer As New OleDbConnection
... because each one opens a new connection. ... Private mConnection As OleDBConnection
... (microsoft.public.dotnet.languages.vb) - Re: CPU 100%
... Kbytes thru a really clean connection. ... If you have DSL and
you are not getting 200 Kbytes look carefully at your ... > Hi Frank - can't really
see what help you're providing Frank? ... (microsoft.public.windows.inetexplorer.ie6.browser) - RE: Setting up queries to run on a schedule
... "Frank" wrote: ... enter a password in order to make a connection. ...
in the query builder that lets me do this. ... each macro would run a single query.
... (microsoft.public.access.queries) - Re: Global Functions
... Dim ConnL3Producer As New OleDbConnection ... because each one opens
a new connection. ... Private mConnection As OleDBConnection ... (microsoft.public.dotnet.languages.vb)