Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Double vs MSSQL Decimal

Hi,

I seem to have a problem when inserting and updating data in an MSSQL database.

I have declared 3 variables:
Dim var1 as double
dim var2 as double

In the database there is a table named Table1 that has 3 coulumns
TID  --> Integer (Primary Key)
C1 --> Decimal (Precision 2)
C2 --> Decimal (Precision 2)

Now when I try to insert or update those 2 doubles to the database I receive an error.
It seems that .NET updates a double like 11,24
MSSQL on his side only seems to accept the format 11.24

Can you help me with this?

Thanks!!!


Jerry
0
Jerry_0001
Asked:
Jerry_0001
  • 3
  • 2
1 Solution
 
rspahitzCommented:
Double is not the same as Decimal.

Technically, Decimal data type is an Integer with implied decimal positions, whereas Double is a Floating Point number.

I'm not sure why you're getting the command, but I would suggest changing one or the other of your data types so they match.
0
 
Jerry_0001Author Commented:
Hi,

Well this project exsits out of 2 phases.
Phase 1 was a survey, that people could fill in.
Phase 2 (now) is the calculation of the results.

Calculate the percentages of each awnser. Problem is that it has to be stored in the database with a precision of 2.
I have to put these results on a website but also in a word doc. Here I can't format the data anwymore.

But I already tried both ways. It doesn't work with decimal nor float.

I always receive this:
"UPDATE resAnon SET a11A = 93,75 and a11B= 6,25 WHERE RID=1"
and I get an error like " Line 1: Incorrect syntax near '75'
0
 
rspahitzCommented:
It appears that you international setting are configured for European (or one variation), and apparently it wants "American" with periods rather than commas as your decimal symbol.

Try looking in Control Panel under international settings.
0
 
rspahitzCommented:
It seems that the International issue in my 2nd comment was the solution.
0
 
Jerry_0001Author Commented:
I'm sorry. Due to some circumstances I haven't been able to go on on this question.

The only way I got further is to do everything with parameters.

MyCommand.Parameters.Add(New SQLParameter("@var1", SQLDataType.VarChar, 11))
MyCommand.Parameters("@var1").Value = var1

That way everything worked...

Thanks for the help!!!!

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now