By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Auto Increment problem

P: n/a
Tom
I am trying to store information into a table that has an auto
increment field. There is currently no data in the table. Using the
code below I cannot insert data into the table. I get an error telling
me that "Number of query values and destination fields are not the
same."

If I add a value for the auto increment field to the SQL String the
data is entered into the table with no problems but obviously the auto
increment field now contains the value I sent to it and not an
incremented number.

Why doesn't the field auto increment when I insert the information for
the rest of the fields? Do I have to initialize the auto increment
number in some way? Please help.

Thanks in advance,

Tom

<% @LANGUAGE="JScript" %>
<!--#include file="adojavas.inc"-->

<%
var dbConnection = Server.CreateObject("ADODB.Connection");
dbConnection.ConnectionTimeout = 30;
dbConnection.Provider="Microsoft.Jet.OLEDB.4.0";
dbConnection.Open("C://Documents and
Settings//thomas.mccardle//Work//data//qvquest.mdb");
if (dbConnection.State == "adStateClosed") {
Response.Write("The database is not available.");

} else {

var SQLString = "INSERT INTO CompanyProfile VALUES ('"
+ Request.Form("CompName") + "', '"
+ Request.Form("Contact") + "', '"
+ Request.Form("Addr") + "', '"
+ Request.Form("City") + "', '"
+ Request.Form("State") + "', '"
+ Request.Form("Zip") + "', '"
+ Request.Form("Tel") + "', '"
+ Request.Form("Email") + "')";
dbConnection.Execute(SQLString);
dbConnection.Close();
Response.Write("The entry has been successfully added.");
}
%>
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You need to specify the field names corresponding to the values you
are inserting. Here's the general format of the INSERT INTO
statement:

INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])

Add the field names in the same order as the values omitting the auto
increment field and you should be in business.

Rick Collard
www.msc-lims.com

On 16 Oct 2003 12:45:09 -0700, th*************@Q1Labs.com (Tom) wrote:
I am trying to store information into a table that has an auto
increment field. There is currently no data in the table. Using the
code below I cannot insert data into the table. I get an error telling
me that "Number of query values and destination fields are not the
same."

If I add a value for the auto increment field to the SQL String the
data is entered into the table with no problems but obviously the auto
increment field now contains the value I sent to it and not an
incremented number.

Why doesn't the field auto increment when I insert the information for
the rest of the fields? Do I have to initialize the auto increment
number in some way? Please help.

Thanks in advance,

Tom

<% @LANGUAGE="JScript" %>
<!--#include file="adojavas.inc"-->

<%
var dbConnection = Server.CreateObject("ADODB.Connection");
dbConnection.ConnectionTimeout = 30;
dbConnection.Provider="Microsoft.Jet.OLEDB.4.0" ;
dbConnection.Open("C://Documents and
Settings//thomas.mccardle//Work//data//qvquest.mdb");
if (dbConnection.State == "adStateClosed") {
Response.Write("The database is not available.");

} else {

var SQLString = "INSERT INTO CompanyProfile VALUES ('"
+ Request.Form("CompName") + "', '"
+ Request.Form("Contact") + "', '"
+ Request.Form("Addr") + "', '"
+ Request.Form("City") + "', '"
+ Request.Form("State") + "', '"
+ Request.Form("Zip") + "', '"
+ Request.Form("Tel") + "', '"
+ Request.Form("Email") + "')";
dbConnection.Execute(SQLString);
dbConnection.Close();
Response.Write("The entry has been successfully added.");
}
%>


Nov 12 '05 #2

P: n/a
Tom
Hi,

Thanks for taking the time to respond and thanks for your help. I
added the specific fields to my SQLString and it worked like a charm.

Have a good day,

Tom
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.