Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC Error

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
Hi,

I am inserting info into a database and it does perform the insert, however, I am getting this error at the end of the action page:
ODBC Error Code = 21S01 (Insert value list does not match column list)

" [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same."

I am first inserting data in a users table, and then I am also adding the username variable into another table which are two separate queries.

The code to insert the data into a DB is as follows:
<CFQUERY DATASOURCE = &quot;ONLINE&quot; NAME=&quot;Search_DB&quot;>
SELECT UserName
FROM Users
WHERE Users.UserName = '#Form.UserName#'
</CFQUERY>

<HTML>
<HEAD>
<TITLE>Verification Details</TITLE>
</HEAD>
<BODY>

<!-- If Variable Username <> UserName entered by user then enter the details in the Users Table-->

<CFIF #SEARCH_DB.RECORDCOUNT# IS 0>
<CFQUERY DATASOURCE = &quot;ONLINE&quot;>
INSERT INTO USERS (UserName, Name, Surname, Password, Email, PasswordReminderQuestion, PasswordReminderAnswer, UserDirectory)
VALUES ('#UserName#', '#Name#', '#Surname#', '#Password#', '#Email#', '#PasswordReminderQuestion#', '#PasswordReminderAnswer#', '#USERNAME#' )
</CFQUERY>
<!--- If the above expression is true i.e. no records of username in db, then the username value is also entered into the userspecific table --->
<CFQUERY DATASOURCE = &quot;ONLINE&quot;>
INSERT INTO USERSPECIFIC (UserName)
VALUES ('#UserName#')
</CFQUERY>
<CFDIRECTORY ACTION =&quot;Create&quot; DIRECTORY = &quot;c:\webshare\


The error above is then present in my other templates.

Any ideas??

Many thanks
Sam
 
Problem is simple, solution is easy:

<CFQUERY DATASOURCE = &quot;ONLINE&quot;>
INSERT INTO USERSPECIFIC (UserName)
VALUES ('#UserName#')
</CFQUERY>

If you look at this query, it looks like the USERSPECIFIC table has only one field. I'll bet you 10 bucks (that's what you call it in the USA I believe...) ;-) that your table has more fields, and that you want to update the record. In that case the query should be:


<CFQUERY DATASOURCE = &quot;ONLINE&quot;>
UPDATE USERSPECIFIC
SET UserName='#UserName#'
WHERE ... put your condition here (ID=#UserId# or something)
</CFQUERY>

if you really have to INSERT (create a new record), make sure you specify all available columns in your INSERT query (except from autonumbers). Hope this helps...
<webguru>iqof188</webguru>
 
Iqof 188, U owe me £10 (in from UK, not USA) :p

You are right, the userspecifc table has more than one column name, but I am just tring to insert into the first field only, all other fields are blank (I dont want to populate the row).
Basically, the users table is linked to the userspecific table via a relationship i.e. users has a primary key field called username and userspecific also has a field called username and they are both linked

Any ideas?
Thanks

sam

PS..if you can help, i'll cancel the £10 you owe me :)
And where are you from?
 
Okay, this should be the query then (INSERT only works if you specify ALL columns):

<CFQUERY DATASOURCE = &quot;ONLINE&quot;>
INSERT INTO USERSPECIFIC (UserName, Field1, Field2)
VALUES ('#UserName#', NULL, NULL)
</CFQUERY>

Show me the money!





<webguru>iqof188</webguru>
 
Thanks iqof188.

Your suggestion has given me fuel for thought, howvever, I think my database was corrupt (I reckon) so I used my backup and the problem has now gone How strange!

Ive put up another thread...Performing multiple updates..
Maybe you an help me out :)

How would you like the money ? :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top