473,403 Members | 2,293 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,403 software developers and data experts.

Problems With Insert Query with Auto Number field

8
Hi All,

I'm trying to insert record to Access DB to a tbale that contains
its first field as AutoNumber field using the following command:

Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO Threads VALUES (" + category + "')";
And it gives me the following error: "Number of query values and destination fields are not the same".

As far as I'm understand I don't need to add the first field because it's AutoNumber, So why this error is always appearing?

Please Help,
10x
Feb 25 '08 #1
1 2043
Stewart Ross
2,545 Expert Mod 2GB
...
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO Threads VALUES (" + category + "')";
And it gives me the following error: "Number of query values and destination fields are not the same".
As far as I'm understand I don't need to add the first field because it's AutoNumber, So why this error is always appearing?...
Hi Liorjj. There are two forms of the INSERT statement: one in which you define the fields to be inserted and their insertion order, and the other in which you don't define the fields and instead rely on implied ordering. It is the implied order version you are using, where the SQL will match the first field in your table to the first item in the VALUES list, the second field to the second item and so on.

Because your autonumber field is the first one you can see that implied ordering is leaving you trying to overwrite this field, as you have not told it the actual name of the field you really want to insert.

You need to explicitly define the field name before your VALUES statement:
Expand|Select|Wrap|Line Numbers
  1.  
  2. "INSERT INTO Threads FIELDS([FieldName]) VALUES (" + category + "')";
  3.  
By the way, you seem to have an extra " ' " character at the end of your statement, before the closing bracket: " ') "

Regards

Stewart
Feb 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: johnnyboy10017 | last post by:
I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that...
5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
1
by: Kosmos | last post by:
Since people have been so helpful on this site I thought I'd contribute what little I can...since I am not a programmer but I'm working on an access database for work The following code is an...
4
by: so many sites so little time | last post by:
ok so i am having problems if you look at the script below you will see that it the query has 4 values to insert but the actual values only contain title entry and now() for the date. well i have...
4
by: John | last post by:
Hi I am using a query to insert a record into a table that has a auto number ID field. I need to retrieve this ID so I can link the child records with it. How can I achieve that?
11
by: jjkeeper | last post by:
Hi, I need to create an annual leave Database for the company. I admit I was a complete novice at this. But I got thrown the job and I have to do it. So here's what I get so far, but I got pretty...
3
by: alexdavies82 | last post by:
I am having a problem producing a relatively simple PHP code. Whenever I run it it gives the following fault message:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
0
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...

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.