473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Getting the value of the next Autonumber

I am using ASP.NET to insert records into a Microsoft Access Database. My
primary keys are of type Autonumber. However, because some of the tables
have relationships I need to know the value of the Autonumber field when I
use the Insert command so that I can put it in the foreign key field of
other tables. I am using VB.NET to code my ASP.NET application. How can I do
this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
4 2115
Hi,

Here is an example

http://support.microsoft.com/default...Product=adonet

--
Val Mazur
Microsoft MVP

http://xport.mvps.org

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
I am using ASP.NET to insert records into a Microsoft Access Database. My
primary keys are of type Autonumber. However, because some of the tables
have relationships I need to know the value of the Autonumber field when I
use the Insert command so that I can put it in the foreign key field of
other tables. I am using VB.NET to code my ASP.NET application. How can I
do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
Nathan,

What you need to do directly after an update or insert is

dim cmd as New OleDbCommand("SELECT @@IDENTITY", conn)
dim mylastId = cmd.executescalar

I hope this helps,

Cor
"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:ec**************@TK2MSFTNGP12.phx.gbl...
I am using ASP.NET to insert records into a Microsoft Access Database. My
primary keys are of type Autonumber. However, because some of the tables
have relationships I need to know the value of the Autonumber field when I
use the Insert command so that I can put it in the foreign key field of
other tables. I am using VB.NET to code my ASP.NET application. How can I
do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #3
I think I understand most of that, except for one thing:

When executing the command, how does it know what table to get it from? I
have multiple tables in my DB, and different tables have different numbers
of records. How does it know which table to get the last value from?

Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Nathan,

What you need to do directly after an update or insert is

dim cmd as New OleDbCommand("SELECT @@IDENTITY", conn)
dim mylastId = cmd.executescalar

I hope this helps,

Cor
"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:ec**************@TK2MSFTNGP12.phx.gbl...
I am using ASP.NET to insert records into a Microsoft Access Database. My
primary keys are of type Autonumber. However, because some of the tables
have relationships I need to know the value of the Autonumber field when I
use the Insert command so that I can put it in the foreign key field of
other tables. I am using VB.NET to code my ASP.NET application. How can I
do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Nov 19 '05 #4
In Access the @@IDENTITY is the identity from last table you updated on your
connection.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
I think I understand most of that, except for one thing:

When executing the command, how does it know what table to get it from? I
have multiple tables in my DB, and different tables have different numbers
of records. How does it know which table to get the last value from?

Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Nathan,

What you need to do directly after an update or insert is

dim cmd as New OleDbCommand("SELECT @@IDENTITY", conn)
dim mylastId = cmd.executescalar

I hope this helps,

Cor
"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:ec**************@TK2MSFTNGP12.phx.gbl...
I am using ASP.NET to insert records into a Microsoft Access Database. My
primary keys are of type Autonumber. However, because some of the tables
have relationships I need to know the value of the Autonumber field when
I use the Insert command so that I can put it in the foreign key field of
other tables. I am using VB.NET to code my ASP.NET application. How can I
do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phillip J. Allen | last post by:
Hi all, I have a table with an “autonumber” primary key field that also acts as a foreign key in 2 other tables. I would like to programmatically add a new record to the first table and the...
2
by: Megan | last post by:
Hi everybody- I have 2 tables, Hearings and Rulings. Both have primary keys called, CaseID, that are autonumbers. I don't want both tables to have the same autonumber. For example, if Hearings...
4
by: DHRRush | last post by:
I have a simple complaint tracking Db with one main table and one main form for entering data. I need for the users to be able to see the record number for future reference when they come back to...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
5
by: marko | last post by:
I would like my autonumber field to start at 100000. How can i do that?
1
by: kchatel | last post by:
Is it possible in Access to do the following. I filtered my table to have the folowing values ProdID Color ------------------------ 2 Black 2 Red 2 Green Now is...
6
by: PeteCresswell | last post by:
Got a table with "RecordID"=AutoNumber=PrimaryKey. Call it "tblIssuerRating". Ran a query that appends to that table from a work table. Inadvertantly appended from the work table's...
12
by: magmike | last post by:
Accidentally deleted a record. Anyway to get it back? If not, I know the ID number - which is an autonumber field. Because of the related data from other tables, would I be able to create a new...
6
by: Wayne | last post by:
I'm using the following SQL statement to find the next highest autonumber value in a table where "CDUGActID is the autonumber field in the "CDUGActuals" table: SELECT CDUGActuals.CDUGActID,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.