Solved

ASP.NET/ ADO.NET Access 97 Autonumber

Posted on 2004-04-21
5
360 Views
Last Modified: 2008-03-03
Hi,

I have an access 97 database that I am writing data to through .NET.  The table I'm inserting data into has an autonumber column for the primary key.  I need to have that primary key return to the .NET layer so I can do other things with it.  I have done my insert through a straight SQL call, and through a DataAdapter -- they both work fine.  However, I cannot get the Primary Key returned.  I found out that you cannot do a "Select @@IDENTITY" because it is Access 97.  How can I get the primary key for an newly inserted row effectively?

Thanks
0
Comment
Question by:srobia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 43 total points
ID: 10882250
you can do "select YourAutonumber from Table"

where YourAutonumber is the name of the Autonumber field
0
 
LVL 10

Assisted Solution

by:EBatista
EBatista earned 41 total points
ID: 10882409
use the RowUpdated event from the OleDbDataAdapter:
(the code below is from MSDN)
...........................
<code to set up and adding data to dataset>
' Include an event to fill in the Autonumber value.

AddHandler catDA.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)

catDA.Update(catDS, "Categories")
.........................

the event handler:
Private Shared Sub OnRowUpdated(sender As Object, args As OleDbRowUpdatedEventArgs)
    ' Include a variable and a command to retrieve the identity value from the Access database.
    Dim newID As Integer = 0
    Dim idCMD As OleDbCommand = New OleDbCommand("SELECT @@IDENTITY", nwindConn)

    If args.StatementType = StatementType.Insert
      ' Retrieve the identity value and store it in the CategoryID column.
      newID = CInt(idCMD.ExecuteScalar())
      args.Row("CategoryID") = newID
    End If
End Sub

hope this help
0
 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 41 total points
ID: 10883251
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question