Hi.
I'm inserting a record into a DB, how do i get the value back of an
AutoNumber field so i can use it in subsequent SQL statements?
At the moment I have code vaguely like this:
Dim selectCMD As OleDbCommand = New OleDbCommand("I NSERT into AuditItems (
ParentAuditID, section, score, comments) values('1')", conn)
MsgBox(selectCM D.ExecuteNonQue ry())
I presume this is quite easy, maybe i'm doing it the wrong way...
Thanks for any help in advance!
Rgds,
Dan 4 1423
i cringe hearing "autonumber"... you must be using access! i don't think you
can afaik.
in msde (which is FAR better than access) you can just append this statement
"select @@identity newId" to the tail end of an insert statment and get the
value from the newId column of the returned recordset.
hth,
steve
"Dan Keeley" <ma********@hot mail.com> wrote in message
news:i1******** *********@newsf ep4-winn.server.ntl i.net... Hi.
I'm inserting a record into a DB, how do i get the value back of an AutoNumber field so i can use it in subsequent SQL statements?
At the moment I have code vaguely like this:
Dim selectCMD As OleDbCommand = New OleDbCommand("I NSERT into AuditItems ( ParentAuditID, section, score, comments) values('1')", conn)
MsgBox(selectCM D.ExecuteNonQue ry())
I presume this is quite easy, maybe i'm doing it the wrong way...
Thanks for any help in advance!
Rgds, Dan
"Dan Keeley" <ma********@hot mail.com> schrieb Hi.
I'm inserting a record into a DB, how do i get the value back of an AutoNumber field so i can use it in subsequent SQL statements?
At the moment I have code vaguely like this:
Dim selectCMD As OleDbCommand = New OleDbCommand("I NSERT into AuditItems ( ParentAuditID, section, score, comments) values('1')", conn)
MsgBox(selectCM D.ExecuteNonQue ry())
I presume this is quite easy, maybe i'm doing it the wrong way...
It's probably already been discussed at
microsoft.publi c.dotnet.framew ork.adonet. Have a look there.
--
Armin
Excellent thanks.
The answer truns out to be:
selectCMD.Comma ndText = "Select @@identity"
MsgBox(selectCM D.ExecuteScalar ())
I will certainly trawl the microsoft newsgroup a bit now.
Thanks again!
Dan
"Armin Zingler" <az*******@free net.de> wrote in message
news:Om******** ******@TK2MSFTN GP12.phx.gbl... "Dan Keeley" <ma********@hot mail.com> schrieb Hi.
I'm inserting a record into a DB, how do i get the value back of an AutoNumber field so i can use it in subsequent SQL statements?
At the moment I have code vaguely like this:
Dim selectCMD As OleDbCommand = New OleDbCommand("I NSERT into AuditItems ( ParentAuditID, section, score, comments) values('1')", conn)
MsgBox(selectCM D.ExecuteNonQue ry())
I presume this is quite easy, maybe i'm doing it the wrong way...
It's probably already been discussed at microsoft.publi c.dotnet.framew ork.adonet. Have a look there.
-- Armin
Dan,
I suggest that you look for a copy of David Sceppa's book 'ADO.NET
Core Reference' which goes over this (and the requirements to make it work
correctly). The book is very useful and has a lot of examples.
Ron Allen
"Dan Keeley" <ma********@hot mail.com> wrote in message
news:7q******** *********@newsf ep4-winn.server.ntl i.net... Excellent thanks.
The answer truns out to be:
selectCMD.Comma ndText = "Select @@identity"
MsgBox(selectCM D.ExecuteScalar ())
I will certainly trawl the microsoft newsgroup a bit now.
Thanks again! Dan
"Armin Zingler" <az*******@free net.de> wrote in message news:Om******** ******@TK2MSFTN GP12.phx.gbl... "Dan Keeley" <ma********@hot mail.com> schrieb Hi.
I'm inserting a record into a DB, how do i get the value back of an AutoNumber field so i can use it in subsequent SQL statements?
At the moment I have code vaguely like this:
Dim selectCMD As OleDbCommand = New OleDbCommand("I NSERT into AuditItems ( ParentAuditID, section, score, comments) values('1')", conn)
MsgBox(selectCM D.ExecuteNonQue ry())
I presume this is quite easy, maybe i'm doing it the wrong way...
It's probably already been discussed at microsoft.publi c.dotnet.framew ork.adonet. Have a look there.
-- Armin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jan Hendrickx |
last post by:
Hi all,
I use (something like) following code to add new records to a database,
but it doesn't work!!!
I need to know the value of an AutoNumber-field when I add the record.
Why doesn't it work and how can I make it work???
I think it should be easy, but I can't figure it out!
|
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 other 2 child tables. The reason
for doing this is to copy one complete record (parent and child table
records) into a new record so the user can make a few modifications.
So how do I determine what will be the next auto-generated number for my...
|
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 has 55, then I want Rulings
to have a number greater than 55. Two or more Hearings may be entered
before a Ruling is entered. For example, Hearings with CaseIDs= 55,
56, and 57 may be entered before a Ruling or vice versa. There is no
definite...
|
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 the
application to update or close that record. The record number is field
RecordId and is an AutoNumber field. (Also the primary key) Is there a
way to show the AutoNumber value in the form when a new record is
opened?
|
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 it.
Simple database: I want to have a user enter Supply Orders (just for
tracking purposes) by Item. The user may also enter a new item - "new"
is a combination of Item, PartNumber and Vendor - they could have the
| |
by: marko |
last post by:
I would like my autonumber field to start at 100000. How can i do that?
|
by: jmar |
last post by:
I'm hoping someone out there can give me a little guidance. I have
an Access Database "Customer.MDB" with a table "CustInfo" that
has the following design:
Field: DataType
CustID AutoNumber
Name Text
Title Text
Phone Text
|
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 "RecordID", which was not
autonumber and, in fact, contained a zero.
The query ran successfully and I would up with a tblIssuerRating
|
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, CDUGActuals.ActualTonnes, +1
AS NextID
FROM CDUGActuals;
This works well as long as no autonumber values have been skipped due
to deletions or cancelled entries. Is there a simple change I can
|
by: Richard Sherratt |
last post by:
I've inherited a system that was designed by someone with no
understanding of database design. From the logical design point of
view, there is no logical design. The physical design is a nightmare.
e.g. there are no relationships between tables and foreign keys appear
to have been sprinkled at random like confetti. As an example, the
Employer - Employee - Contract - Expense hierarchy has EmployerID in
the Expense table. That's the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |