Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 inserting into a money field in sql
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 05 May 2001 :  15:36:27  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
can anyone tell me why this is not working? i thought that 39.99 is in the format fto be inserted into a money field




Insert Into ExhibitParts_Orders (OR_Customer_ID, OR_Date_Ordered, OR_Product_Total, OR_Shipping_N_Handling_Total, OR_Taxes_Total, OR_Products_Ordered) VALUES ('1', '5/5/2001', '39.99', '1.11', '1.11', '4-26-39.99|')
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC SQL Server Driver][SQL Server]Disallowed implicit conversion from data type varchar to data type money, table 'freeaspcodesql.dbo.ExhibitParts_Orders', column 'OR_Product_Total'. Use the CONVERT function to run this query.

/exhibitparts/store/checkout.asp, line 37


Brad

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 05 May 2001 :  15:50:23  Show Profile  Visit HuwR's Homepage
money is a numeric value and therfore should not be siurrounded by ''

Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 05 May 2001 :  17:53:40  Show Profile
quote:
'4-26-39.99|'

And what's the other stuff in the field? Shouldn't it just be 39.99 ?


======
Doug G
======
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 05 May 2001 :  19:02:59  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
the other field is the orders. i really didnt know how to insert them into the database so i just did it like that. it works and i havnt had a problem yet. here is how it works

the first number is the product id, the second is how many they ordered, the third is the price

Brad
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 05 May 2001 :  21:50:20  Show Profile
Ah-ha! I didn't even see the other 39.99, I fixated on the one at the end and said 'huh?' :)

======
Doug G
======
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 06 May 2001 :  16:02:43  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message


now one more question.....

for some reason this is not adding can you tell me why?


<%
strFirst = "39.99"
strSecond = "10.99"

strTotal = strFirst + strSecond

Response.Write strTotal
%>


Brad
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 06 May 2001 :  16:10:52  Show Profile  Visit HuwR's Homepage
quote:

<%
strFirst = "39.99"
strSecond = "10.99"
strTotal = strFirst + strSecond
Response.Write strTotal%>



You are trying to add two strings as if they were numbers, try this

dblFirst = 39.99
dblSecond = 10.99
strTotal = dblFirst + dblSecond
Response.Write strTotal



Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 06 May 2001 :  16:21:17  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
huwr,

that worked but the real code is like this. i just wrote that so it would be easier to understand...


' LETS MAKE SURE SOMETHING IS IN THE SHOPPING CART
cempty=true
strProductPrice = ""
for i=lbound(arrCart) to ubound(arrCart)
if arrCart(i,0)<>"" and arrCart(i,1)<>"" and arrCart(i,2)<>"" then
strCartString = strCartString & arrCart(i,0) & "-" & arrCart(i,1) & "-" & arrCart(i,2) & "|"
strProductPrice = arrCart(i,2)

strProductTotalPrice = strProductTotalPrice + strProductPrice
cempty=false
end if
next

if cempty then
' cart empty
Response.Write "cart empty"
else
' cart not empty
if strProductTotalPrice = "" then
strProductTotalPrice = "0.00"
end if
if strProductShippingNHandling = "" then
strProductShippingNHandling = "0.00"
end if
if strTaxesTotal = "" then
strTaxesTotal = "0.00"
end if

strSQL = "Insert Into ExhibitParts_Orders (OR_Customer_ID, OR_Date_Ordered, OR_Product_Total, OR_Shipping_N_Handling_Total, OR_Taxes_Total, OR_Products_Ordered) VALUES ('" & strCookieCustomerID & "', '" & Date & "', " & strProductTotalPrice", " & strProductShippingNHandling & ", " & strTaxesTotal & ", '" & strCartString & "')"
Response.Write strSQL
my_Conn.Execute (strSQL)
end if


and the output of the sql string is....

Insert Into ExhibitParts_Orders (OR_Customer_ID, OR_Date_Ordered, OR_Product_Total, OR_Shipping_N_Handling_Total, OR_Taxes_Total, OR_Products_Ordered) VALUES ('1', '5/6/2001', 39.999.99, 0.00, 0.00, '4-7-39.99|1-6-9.99|')

I have two products that are in an array one is 39.99 and the other is 9.99.

i hope this makes since, if it doesnt ill try to explain more, but its just not working

Brad
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 06 May 2001 :  17:58:35  Show Profile  Visit HuwR's Homepage
okay try this

strProductTotalPrice = cDbl(strProductTotalPrice) + cDbl(strProductPrice)

Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 07 May 2001 :  08:18:40  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
thanks that works great, but what is...

cDbl

should i use this when adding any dollar amount?

Brad
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 07 May 2001 :  08:36:12  Show Profile  Visit HuwR's Homepage
it converts a string into a floating point number of type double much the same as cInt makes it an integer

you could also use cCur - currency type or cSng - single Type floating point

take for instance this number

19.2254576 which is of type double

cCur(19.2254576) = 19.2255
sSng(19.2254576) = 19.22546

Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 07 May 2001 :  08:39:21  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
lol

cant this be simple?

Brad
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 1.21 seconds. Powered By: Snitz Forums 2000 Version 3.4.07