Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2006, 11:17 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default data mismatch while updating record

Hi there,

I'm a novice in ASP, I'm stuck in this issue:

I've an existing table "Item" with columns of "Qty" and "AveragePrice". When users add some more items on it, the code supposes to update the AveragePrice based on the newly added quantity and price.

Qty is Integer and AveragePrice is Money with lenght 8. But when I was trying to do "update" in following code, it tells me to use CAST or CONVERT to explicitly convert the data type. But I've tried with CAST(newAverage AS money) or CONVERT(money, newAverage), both got error messages. Actually the piece of code was existing before, but the AveragePrice column is what I'm trying to add.

================================
Dim Item2
set Item2 = Server.CreateObject ("ADODB.Recordset")
Item2.Open SQL, conn

Dim newQTY, oldQTY, oldAverage, newAverage
if not Item2.EOF then
  oldQTY = Item2("Qty")
  oldAverage = Item2("AveragePrice")
  newQTY = oldQTY + CLng(qty) 'qty given some time before
  newAverage = ( oldQTY * oldAverage + CLng(qty) * cost ) / ( oldQTY + CLng(qty)))

  SQL = "update Item " &_
    "set Qty = '" & newQTY & "', AveragePrice = '" & newAverage & "' " &_
    "WHERE ItemID = '" & itemID & "'"
End if
============================

I've tried to change the newAverage in the line "update Item..." to CAST(newAverage AS money) or CONVERT(money, newAverage), seems both not working.

Looking forward eagerly to some help

Thanks a lot
Tropical

Reply With Quote
  #2 (permalink)  
Old March 7th, 2006, 12:38 PM
Friend of Wrox
 
Join Date: Nov 2005
Location: Rotterdam, , Netherlands.
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

a quick guess is that your trying to put a string value where the type is integer.
try this
Code:
'convert string to integer
Cint(newAverage)
__________________________________________________ ________
This is my junk I'm gona eat it
Reply With Quote
  #3 (permalink)  
Old March 7th, 2006, 06:23 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

If you are inserting into an integer field you dont need '" "' You need " " Eg:

SQL = "UPDATE Item SET Qty = " & cint(trim(newQTY)) & ", AveragePrice = '" & trim(newAverage) & "' WHERE ItemID = '" & itemID & "';"

Its a good habbit to use the trim function in you sql and use a trailing semi colon (as you can see above)

What data type is the field ItemID? Once agin you have '" "' if this is an integer remove the single quotes Eg:

SQL = "UPDATE Item SET Qty = " & cint(trim(newQTY)) & ", AveragePrice = '" & trim(newAverage) & "' WHERE ItemID = " & itemID & ";"



Wind is your friend
Matt
Reply With Quote
  #4 (permalink)  
Old March 8th, 2006, 03:33 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks DJ Kat and Mat41.

Thank you so much for your answers, I've fixed this error based on your suggestion.

Since AveragePrice's data type is money, so I should use " & newAverage & " instead of '" & newAverage & "'.

Reply With Quote
  #5 (permalink)  
Old March 8th, 2006, 09:02 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

You are welcome

;;Since AveragePrice's data type is money, so I should use " & newAverage & " instead of '" & newAverage & "'.

Is that a question?

FYI: Run the statement with the " " if it doesnt work use '" "' is generally a good way to figure solve this problem

Wind is your friend
Matt
Reply With Quote
  #6 (permalink)  
Old March 8th, 2006, 09:56 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, it's not a question. That's how I fixed the error.

That's a very useful suggestion, always try " " when '""' doesn't work, because that was exactly my issue.

Thanks again, Mat41

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating database record shrisangeeta Classic ASP Basics 4 February 28th, 2007 05:25 PM
Updating the record in the database lwebzem ASP.NET 1.0 and 1.1 Basics 3 February 28th, 2006 07:57 AM
Updating first found record rtr1900 Classic ASP Databases 9 December 2nd, 2005 03:09 AM
updating record stoneman Access 1 July 5th, 2005 09:12 AM
Record not updating Tangerine ASP.NET 1.x and 2.0 Application Design 3 March 24th, 2004 12:00 PM



All times are GMT -4. The time now is 01:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.