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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing decimal(price) to stored procedure

Status
Not open for further replies.
May 20, 2003
9
0
0
US
I'm new to all this, but I have to make a prototype of a legacy system I worked on.

Using ASP to present the info to the user I have an INPUT field that will be used to display and update a price, defined as a decimal(7,2) in a SQL Server 2000 database.

When I create the parameter to pass to the stored procedure, I have used

curPrice = CDBL(TRIM(request("txtPrice"))) and then create the parameter to pass to the stored procedure using the variable:

cmdParts.Parameters.Append cmdParts.CreateParameter ("@PRICE", addecimal, adParamInput, , curPrice)

I also tried it like this:

cmdParts.Parameters.Append cmdParts.CreateParameter ("@PRICE", addecimal, adParamInput, , CDbl(Trim(request("txtPrice"))))

The stored procedure has the parameter defined as

REATE PROCEDURE ADD_ITEM_DETAIL
(@ITEMSEQ Int
,@ITEMDETAILDESC varchar(50)
,@PRICE decimal(7,2)
,@REQUIRED char(01)
,@ACTIVE char(01)
)

and the field is defined in the database as a decimal(7,2)

And I get this....

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
/CE/Maintenance/Plans/UpdatePlanCodeInfo.asp, line 93


I've removed all references to the 'price' and I can add rows without a problem.

So... how do you get a price (7.25) from the HTML to the stored procedure and get it updated? Somewhere on the way it appears I am encountering a data type conversion problem of some kind.

I've tried to redefine the field as Money vs. decimal.

Regards.
 
This should work.... How are you unsing the value in the SP?

curPrice = TRIM(request("txtPrice"))

cmdParts.parameters(2) = curPrice

....

CREATE PROCEDURE ADD_ITEM_DETAIL
(@ITEMSEQ Int
,@ITEMDETAILDESC varchar(50)
,@PRICE money
,@REQUIRED char(01)
,@ACTIVE char(01)
)

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
In the stored procedure I am inserting a row into a table.

Insert into tblItemDetail
...
Price,
...

Values
(...
,@PRICE)
...
)


 
Everything still looks alright here, what dataType is Price in your database?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top