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

insert decimal value

Status
Not open for further replies.

lin73

Programmer
Feb 17, 2006
110
0
0
SE
Hi

I need to pass a decimal value into a stored procedure but can't get it to work as it should. I have this code that works for a integer, but how do I change it so it works for decimal value?

cmd.Parameters.Append cmd.CreateParameter("@Price", 3, 1,4,cmd__PriceD)

 
cmd.Parameters.Append cmd.CreateParameter("@Price", [!]3[/!], 1,4,cmd__PriceD)

That 3 identifies the data type as Integer. To use a decimal, you need to use 14.

Code:
cmd.Parameters.Append cmd.CreateParameter("@Price", [!]14[/!], 1,4,cmd__PriceD)

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi

Thanks for the info, sorry to say that I cannot verify if it worked.... I now get a "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." error.


 
You need to change the 4th parameter to accomodate the size of the decimal column.

try just making it bigger (like 9).

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi

I have isolated the problem to be the decimal insert. In my stored procedure I have set the decimal value to be "decimal(18, 2)" and then I try to insert this..

Dim iPrice
iPrice = "1.23"

cmd.Parameters.Append cmd.CreateParameter("@Price", 14, 1,4,cmd__Price)


When I remove all my parameters that use decimal the procedure works fine so there must be something wrong about the way I currently pass my decimal value.
 
Made a typo in the above, it should of course be ..

Dim cmd__Price
cmd__Price = "1.23"
 
A decimal(18,2) requires 9 bytes. So....

cmd.Parameters.Append cmd.CreateParameter("@Price", 14, 1,[!]9[/!],cmd__Price)

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi

Even if I change it to that I get the same error message
 
Update...

Got it working using this code....

Set Parm1 = cmd.CreateParameter("@Price",14)
Parm1.Precision = 18
Parm1.NumericScale = 2
Parm1.Value = cmd__Price
cmd.Parameters.Append Parm1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top