ADO.NET decimal parameter

When i update my table i get some annoying rounding.
The SQL table has been set with a scale of 2 (ie 2 to the right of decimal point) If i set it manually in the DB it stays as expected.

Eg. 81.5 stays as 81.5

but when i try and update from my app it gets rounded... 81.5 becomes 82.

...in the dataset its held as i set it via the bound controls. I confirmed this by msgboxing it out..
                                       MsgBox(dsprod.Tables("EDUspecific").Rows(0)("PaymentForefit").ToString)

So the problem lies with the parameters. At first i used the line below.
daProd.UpdateCommand.Parameters.Add(New SqlParameter("@PaymentForefit", SqlDbType.Decimal)).SourceColumn = "PaymentForefit"

Then i tried this other idea which incorporates the scale (set to 2). Still does work.
daProd.UpdateCommand.Parameters.Add(New SqlParameter("@PaymentForefit", SqlDbType.Decimal, _
                                                            9, ParameterDirection.Input, False, 18, 4, "PaymentForefit", _
                                                            DataRowVersion.Current, Nothing))

I printed out @PaymentForefit from the storedprocedure... by then it has been rounded so its 82.

Ideas?!
DSEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RonaldBiemansCommented:
hi DSE,
could you try this

        Dim x As New SqlClient.SqlParameter("@PaymentForefit", SqlDbType.Decimal)
       
        command.Parameters("@out_arg").Direction = ParameterDirection.input
        command.Parameters("@out_arg").Precision = 10
        command.Parameters("@out_arg").Scale = 2
     daProd.UpdateCommand.Parameters.Add(x)
0
RonaldBiemansCommented:
sorry

        Dim x As New SqlClient.SqlParameter("@PaymentForefit", SqlDbType.Decimal)
       
        x.Direction = ParameterDirection.input
        x.Precision = 10
        x.Scale = 2
       daProd.UpdateCommand.Parameters.Add(x)
0
DSEAuthor Commented:
Hi Ronald,

I will try that...

BBIAB
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

DSEAuthor Commented:
alas that hasnt worked.

Is there any specialties i need consider when declaring the parameter in the stored procedure?

currently...

@PaymentForefit as decimal

Regards,
DSE
0
RonaldBiemansCommented:
Strange, I had the same problem, although for an output parameter, and that solved it.
I will try to recreate your problem and I'll get back to you.

0
DSEAuthor Commented:
Thanks for your persistance...
...........................................

CREATE PROCEDURE [dbo].[UpdateEDUspecific]

@PaymentForefit as decimal =null

 AS

print @paymentforefit

.... Its this print that shows me that its been rounded
0
RonaldBiemansCommented:
Hi DSE,

I tried this and this worked,

in my stored procedure i defined my decimal like this

@testje decimal(18,2),

and my parameter looked like this

daProd.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@testje", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(2, Byte), "testje", System.Data.DataRowVersion.Current, Nothing))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DSEAuthor Commented:
Hi Ronald!...

i was just about to post my findings of the same!

Thanks for your help.

The points are yours!

Regards

DSE
0
DSEAuthor Commented:
For future readers id like to add that ive found that you dont need to specify precision and scale in the client side parameter declaration.
Aslong as the receiving procedure's parameter declaration has precision and scale defined it works fine!

DSE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.