473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Access mdb via ODBC - how to return autonumber

Hope someone can help. This is half an Access question. The half I'm
using is Access Xp as a backend data file. I'm using ODBC to connect
to the data file. All commands are via SQL type statements (SELECT,
UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend).

After inserting a record (row) into a table using "INSERT INTO ...."
what is the easiest way to obtain the value of a counter field for the
record just inserted?

I have considered "SELECT Max(CounterFiel d) FROM ....". By using ODBC
is this my only option in retrieving the counter field value?

Thanks in advance.

Steven Taylor
Melbourne, Australia.
Nov 13 '05
33 7648
rkc
Steven Taylor wrote:
Could you elaborate on your comment regarding "Unique field, should
never be a counter".


A counter, usually refered to as an autonumber when using Access/Jet,
is used to uniquely identify a record. It should not be used to make
the data in that record unique. That should come from a combination
of values in fields (not generated by the db engine) that is only ever
allowed to occur once in a table. That is the heart and soul of a
relational database.

I'll have to disagree with you on this one. You even mention "A
counter.....is used to uniqely identify a record". Without the use of
a single field (primary key) to identify a record, creating a 'many to
many' type relationship would be a nightmare. The joining table
(linking table) rather than having a minimun two foreign key fields
would require as many combined fields from each of the primary tables.

I'm not suggesting though, that every table must have a counter as a
primary key, just that it makes it so much simpler to work with if one
is present, if it's going to be related to.

I suppose it comes down to personal preference.

Steve.


A counter is a pointer. It points to a single record. This makes
them useful as a 'key'. The use of a counter does not make the
information represented by a record unique. That, as you obviously
realise, sometimes takes a combination of other fields in the record.

My suggestion to your op was that if you just inserted a record
in a table then you know the values you just used to do it. You
can use the fields that make the record unique to retrieve the
counter assigned to that record by the db engine. The fact that
designers of many db engines provide short cuts for that purpose
is a bonus, I guess.



Nov 13 '05 #21
rkc
Trevor Best wrote:
<snip>
I agree.

In one of my databases, a hierarchy goes like this (usually 1:n)

Project->Order->OrderItem->ExpeditingComp onentSplit->DelSplit->MMTItem[1]->MRRItem[2]
Can you imagine the PK on MRRItem if I didn't use a counter?
ProjectNo + OrderNo + OrderItemNo + CompSplit + DelSplit + MMTNo + MRRNo


The point is that a unique combination of information that makes up a
MRRItem does exists in each MRRItem. The counter does not make each
MRRItem unique.
Nov 13 '05 #22


rkc wrote:
snip
My suggestion to your op was that if you just inserted a record
in a table then you know the values you just used to do it. You
can use the fields that make the record unique to retrieve the
counter assigned to that record by the db engine. The fact that
designers of many db engines provide short cuts for that purpose
is a bonus, I guess.


Yes, I agree.

Steve.
Nov 13 '05 #23
Steven Taylor <ne******@super jacent.net> wrote in
news:42******** *************** @news.optusnet. com.au:

[rkc:]
A counter, usually refered to as an autonumber when using
Access/Jet, is used to uniquely identify a record. It should not
be used to make the data in that record unique. That should come
from a combination of values in fields (not generated by the db
engine) that is only ever allowed to occur once in a table. That
is the heart and soul of a relational database.


I'll have to disagree with you on this one. . ..


I think you're not fully grasping rkc's point (you really ought to
work harder to maintain attributions, too).

Say you've got a table of companies. If you use an AutoNumber as a
PK, but don't put a unique index on company name, then you can end
up with identical companies.

That's all rkc is saying, that if you use an Autonumber as a
surrogate key, you *still* have to enforce uniqueness in the other
fields, insofar as it is physically possible. This usually means
that you have a unique index on the candidate natural primary key
that the surrogate key replaces for ease of use.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #24
rkc <rk*@rochester. yabba.dabba.do. rr.bomb> wrote in
news:4L******** ***********@twi ster.nyroc.rr.c om:
rude person wrote:
On Tue, 19 Jul 2005 08:59:48 +0100, Trevor Best
<no****@besty.o rg.uk> wrote:

Steven Taylor wrote:

>>Could you elaborate on your comment regarding "Unique field,
>>should never be a counter".
>

I agree.


etc

I think the point being made isn't "don't use a counter", it is
that two records shouldn't be exactly the same apart from the
counter


Yes. Exactly that.


Well, except for one point:

You don't mean that the records shouldn't be identical, but that two
records should not refer to a single real-world entity.

With incomplete data, you may end up with two records that look
identical because they are not complete, but actually really do
refer to two different entities. The problem with those is
distinguishing them while you are waiting to get real data.

But you really do sometimes have identical records as a temporary
condition caused by real-world incompleteness.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #25
rkc
David W. Fenton wrote:
rkc <rk*@rochester. yabba.dabba.do. rr.bomb> wrote in
news:4L******** ***********@twi ster.nyroc.rr.c om:

rude person wrote:
I think the point being made isn't "don't use a counter", it is
that two records shouldn't be exactly the same apart from the
counter
Yes. Exactly that.

Well, except for one point:

You don't mean that the records shouldn't be identical, but that two
records should not refer to a single real-world entity. With incomplete data, you may end up with two records that look
identical because they are not complete, but actually really do
refer to two different entities. The problem with those is
distinguishing them while you are waiting to get real data.

But you really do sometimes have identical records as a temporary
condition caused by real-world incompleteness.


The values in the fields that make up the selected real primary key
should never occur more than once in the same combination in the same
table. The design of the table should be such that the db engine
does not allow it. How else can uniqueness be enforced without a doubt?



Nov 13 '05 #26
On Tue, 19 Jul 2005 14:09:44 -0500, "David W. Fenton" <dX********@bwa y.net.invalid> wrote:

....
With incomplete data, you may end up with two records that look
identical because they are not complete, but actually really do
refer to two different entities. The problem with those is
distinguishi ng them while you are waiting to get real data.


Theory and practice sometimes diverge.
I found that if I set a field as "required", users would sometimes enter a valid
but bogus entry and make a mental note to correct it later, rather than have to re-enter
a long record when they knew all the values. It is safer to accept incomplete records
and detect them by program.

Nov 13 '05 #27
David W. Fenton wrote:
snip

I think you're not fully grasping rkc's point (you really ought to
work harder to maintain attributions, too).


I don't follow you re - the above. I'm not sure what you mean by "work
harder to....."

I'm not, and haven't, suggested that other fields can't be defined as
unique or combined to be unique. Merely that a counter number assists
with easier reference to the table.

Steve.
Nov 13 '05 #28
> Where to you find out about these little additions to Jet 4?

They seem to be hidden. I go to Help -> Microsoft Jet SQL reference ->
Overview -> SQL Reserved Words. It seems if MS decided to reserve a
word then they are using the word. If I'm not familiar with its use, it
may be new. When I click on it, it often, but not always, tells me.
For @@Identity, the link takes one to SQL data-types. When I got there,
I saw nothing about @@Identity. But second section from the bottom
describes its use.
I really wanted to use A2K when it came out (in large part because
of the vast improvements in Jet 4 replication), but there were so
many problems with A2K as a development platform that it wasn't
worth it.


I did not agree with you. In retrospect I can't say which of us was
right. Access 2K and especially ADPs (not ADO) brought me to lot of
late night, "What am I gonna do NOW?" situations, because there were
many errors in these technologies, and also because the errors seemed
to be random, unpredictable and erratic; so a solution for Checkbox A,
is not necessarily a solution for Checkbox B, even though they seem to
be identical in use, calling, etc.

Nov 13 '05 #29
ly******@yahoo. ca wrote:
Where to you find out about these little additions to Jet 4?

They seem to be hidden. I go to Help -> Microsoft Jet SQL reference ->
Overview -> SQL Reserved Words. It seems if MS decided to reserve a
word then they are using the word. If I'm not familiar with its use, it
may be new. When I click on it, it often, but not always, tells me.
For @@Identity, the link takes one to SQL data-types. When I got there,
I saw nothing about @@Identity. But second section from the bottom
describes its use.


I'll just add that while that is fine for Jet, if you have a SQL Server
(or MSDE) back end then you'd be better off using SCOPE_IDENTITY( ) as
the @@IDENTITY global var can be influenced by triggers that do inserts.

I'll also add (as I saw it being asked elsewhere in the thread) that in
SQL Server, @@IDENTITY is confined to the connection you're using so
multi-user issues shouldn't be an issue (i.e. you will *not* pick up
someone else's autonumber column value). I assume the same is true for
Jet, I can't imagine it being any different.

--
[OO=00=OO]
Nov 13 '05 #30

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

Similar topics

13
8296
by: Eric E | last post by:
Two questions regarding ODBC. 1) I am connecting to a MySQL database using the following code: Function LoginToMySQL(sUsername As String, sPW As String) As Boolean Dim dbMySQL As Database Dim cnMySQL As DAO.Connection Dim sDSN As String sDSN = "ODBC;DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=127.0.0.1;" _
3
2307
by: Mike | last post by:
Using MS Access XP standard install (no Jet or MDAC updates applied yet) as front end, MySQL 4.0 as backend and MySQL ODBC connector version 3.51. When pasting multiple records into the database either in a form or directly in the table, all records / fields display #deleted in each column. This only happens when pasting multiple records, if a single record is pasted, the #deleted comment does not appear. When I refreash the view, the...
9
3054
by: Paradigm | last post by:
I am using an Access2K front end to a MYSQL database. If I enter a new record in a continuous form the record appears as #deleted as soon as I move to a different record in the form until I requery the form. After the requery the records are in different order to the order that they may be entered in. The record does not seem to be assigned an ID (autonumber ID field) until after it is requeried. My problem is that after requerying the...
42
5657
by: PC Datasheet | last post by:
I have zero experience with using a SQL database for a backend and Access for a frontend. I have some questions: 1. Does an SQL database have tables? 2. How does Access connect to the data in an SQL database? Linking, importing, or ??? 3. Earlier today there was a thread regarding DAO and ADO. In the thread it was said that ADO is very useful when the backend is a SQL database. Could someone explain that?
4
2748
by: David Siroky | last post by:
Hi! I'm trying to connect to a MDB file via ODBC like this: char *DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dev-cpp\\test\\1.mdb"; SQLAllocEnv(&env); SQLAllocConnect(env, &hdbc); SQLBrowseConnect(hdbc, (UCHAR*)DSN,
0
511
by: Steven Taylor | last post by:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type statements (SELECT, UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend). After inserting a record (row) into a table using "INSERT INTO ...." what is the easiest way to obtain the value of a counter field for the record just...
6
14001
by: Andy Barber | last post by:
Hi, I'm trying to write an app that reads data from a table into a string variable for later use in my program. Below is a snippet of the code I'm using, which compiles ok, but at runtime I get and error 'Object reference not set to an instance of an object.' as soon as I try to access the data in the fields, I.e. at the line that reads 'KeyFlags(i) = rstFields("keyflag").value'
15
4745
by: Marcus | last post by:
I created a VB.Net 1.1 application that iterates through all the tables in any basic Access 2000 database passed to it and generates the same table structure in a SQL Server Express database. The structure is created fine (with minor data conversions from one to the other, e.g. yes/no --> bit, memo --> text, etc). My problem now is transferring the data over from Access to SQL Server. I thought it would be a fairly straight forward...
1
2450
by: gordon.dtr | last post by:
Hi, Has anyone had this problem ? I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11 standard log. I created my tables in MS Access, then exported them via ODBC to an externally hosted MySQL database (fasthosts) . I then import-linked
0
9705
marktang
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...
0
10564
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, 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...
0
10073
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 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...
1
7609
isladogs
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...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.