ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 3rd, 2003, 11:47 AM
Richard Doughty Richard Doughty is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 Richard Doughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry ASP Help needed.

Hi, i'm designing a shopping cart system for a freind from a tutorial in a book. Only problem is that the tutorial doesn't include a option for the quantity of a single item in the cart. So i got the whole thing running and then thought i'd add the quantity field in the table cart in the database called tblQuantity. So i did this and now i get this error when i try to add to the cart:

----------

ADODB.Connection.1 error '80004005'

SQLState: S1000
Native Error Code: 1136
[TCX][MyODBC]Column count doesn't match value count at row 1


/store/specials/TMPgdfpqhggkb.asp, line 116

-------

the code for the insert record is below

strUsername = Session("MM_Username")
MM_editQuery = "insert into " & MM_editTable & " values (''," & MM_dbValues & ",'" & strUsername & "','')"

---------

Im sure that it's somthing to do with the insert code not specifing all the fields that need to be updated because when i delete the field in the database i added for the quantity the add to cart works again. i don't know any asp so i havn't a clue what to change so any help would be much appreciated.

Cheers.

Reply With Quote
  #2  
Old July 3rd, 2003, 11:54 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
It's not an ASP issue, but a SQL issue. Unless you specify a field list before "VALUES" in your query, the order and data types of the values you're inserting must match the order and data types of the fields in the database. Maybe you're not building MM_dbValues correctly. For example, if you added the quantity field to the end of your table, but it's being passed as part of MM_dbValues, you'll get an error because you're inserting other values after inserting MM_dbValues, and your insert order doesn't match your actual field order. This can be solved either by sending a properly ordered field list in parentheses before "VALUES."

Reply With Quote
  #3  
Old July 4th, 2003, 04:18 AM
Richard Doughty Richard Doughty is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 Richard Doughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Alright Mate Cheers for the Reply.

Could you give me an example of this as i am not very good with SQL :

" This can be solved either by sending a properly ordered field list in parentheses before "VALUES." "


This -

strUsername = Session("MM_Username")
MM_editQuery = "insert into " & MM_editTable & " values (''," & MM_dbValues & ",'" & strUsername & "','')"

works for inserting a record into this SQL table -

cartID int not null auto_increment,
prodID varchar(50),
username varchar(50),
orderID varchar(50),
primary key (cartID)
)

all i want to do is add a field "prodQuantity" to the table. I don't want it to instert anything into at this stage. Just for it to be part of the table so i can use it later on.

Thanks for the help.

Reply With Quote
  #4  
Old July 4th, 2003, 11:23 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You need to take dhouston's advice. Essentially, what the error message is saying is that the number of fields you have in the FIELDS section of the SQL statement outnumber the VALUES section.

e.g. INSERT INTO foo (field1, field2, field3) VALUES (value, value2)

This is incorrect. They need to match up.

90% of all programming problems can be solved if you simply print out the value of the variable that you're having problems with. In this case, print out your SQL string BEFORE executing it. This will allow you to see what's going wrong.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #5  
Old July 7th, 2003, 09:13 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
To extend stumpy's example a little, let's pretend you've got a three-column table. The columns are named "one," "two," and "three." Your initial query is:

Quote:
INSERT INTO table_name VALUES("val one","val two","val three");


Now you want to add a column named "four" to your table. Your original query will break because the default behavior of a query without a field list preceding VALUES is to compare your VALUES list to the full table schema and to bomb if the field types or the number of fields don't match the full table schema. The solution is one of the following:

Quote:
INSERT INTO table_name (one, two, three) VALUES ("val one","val two","val three");


or

Quote:
INSERT INTO table_name VALUES ("val one", "val two", "val three", "");


See that if you don't give a column list and the items you're inserting don't match up to what's in the table, you need to put placeholders in the spots you don't have values for. So I've got empty quotes as the fourth value in the second revised query above.

Reply With Quote
  #6  
Old July 7th, 2003, 09:17 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
For code re-ability, it's always advisable to use the full INSERT notation. i.e.
Code:
INSERT tablename (fieldname_list) VALUES (values)
It'll make things easier on you, and anyone else who might need to work on your code at a later time.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > SQL - insert logic error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT