Jerry_0001
asked on
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
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
ASKER
Hi Suku,
Thank for the help already.
What I did is the following:
Dim yes As Integer = 0
Dim no As Integer = 0
Dim totyes As Double = 0
Dim totno As Double = 0
strSQL = "SELECT COUNT(*) FROM part1 WHERE awnser = 1"
com = New SqlCommand(strSQL, conn)
yes = com.ExecuteScalar()
no = total - yes
totyes = (yes / total) * 100
totno = (no / total) * 100
strSQL = "UPDATE tableTot SET a1A = " & totyes & " and a1B= " & totno & "' WHERE RID=1"
When this is executed the Auto's window gives this result:
"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'
Thanks again,
Jerry
Thank for the help already.
What I did is the following:
Dim yes As Integer = 0
Dim no As Integer = 0
Dim totyes As Double = 0
Dim totno As Double = 0
strSQL = "SELECT COUNT(*) FROM part1 WHERE awnser = 1"
com = New SqlCommand(strSQL, conn)
yes = com.ExecuteScalar()
no = total - yes
totyes = (yes / total) * 100
totno = (no / total) * 100
strSQL = "UPDATE tableTot SET a1A = " & totyes & " and a1B= " & totno & "' WHERE RID=1"
When this is executed the Auto's window gives this result:
"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'
Thanks again,
Jerry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I changed everything to this now, but now I get the error: "Must declare the variable '@totyes'
strSQL = "SELECT COUNT(*) FROM part1 WHERE awnser = 1"
com = New SqlCommand(strSQL, conn)
yes = com.ExecuteScalar()
no = total - yes
totyes = (yes / total) * 100
totno = (no / total) * 100
com.Parameters.Add(New SqlParameter("@totyes", SqlDbType.Decimal, 5)).Value = totyes
com.Parameters.Add(New SqlParameter("@totno", SqlDbType.Decimal, 5)).Value = totno
strSQL = "UPDATE tableTot SET a1A = @totyes and a1B= @totno WHERE RID=1"
Do you know what can be the problem here?
strSQL = "SELECT COUNT(*) FROM part1 WHERE awnser = 1"
com = New SqlCommand(strSQL, conn)
yes = com.ExecuteScalar()
no = total - yes
totyes = (yes / total) * 100
totno = (no / total) * 100
com.Parameters.Add(New SqlParameter("@totyes", SqlDbType.Decimal, 5)).Value = totyes
com.Parameters.Add(New SqlParameter("@totno", SqlDbType.Decimal, 5)).Value = totno
strSQL = "UPDATE tableTot SET a1A = @totyes and a1B= @totno WHERE RID=1"
Do you know what can be the problem here?
ASKER
Problem solved.
Thanks for the tip.
Thanks for the tip.
Hi,
i think it is a globalization issue. your sql sqlver and asp.net application might use different settings..
use sp_helplanguage @@LANGUAGE to set sql server settings.
if u want to change in asp.net cheack the glabalization settings in web.config.
Suk
i think it is a globalization issue. your sql sqlver and asp.net application might use different settings..
use sp_helplanguage @@LANGUAGE to set sql server settings.
if u want to change in asp.net cheack the glabalization settings in web.config.
Suk
SQL wouldn't accept comma as decimal pointer. it will treat it as two parameter values. format the value before u sent.
if possible post the error u r getting that will help us to understand the prob..
Suku