• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2087
  • 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
 
sukumar_diyaCommented:
hi Jerry,
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
0
 
Jerry_0001Author Commented:
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
0
 
Sammy AgeilCommented:
Jerry,
Use sqldatatype instead of VB datatypes.
MyCommand.Parameters.Add(New SQLParameter("@var1", SQLDataType.VarChar, 11))
MyCommand.Parameters("@var1").Value = var1

more here
http://www.asp.net/QuickStart/aspnet/doc/ctrlref/data/detailsview.aspx
http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/data/GridViewMasterDetailsInsertPage.src

Good luck
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Jerry_0001Author Commented:
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?
0
 
Jerry_0001Author Commented:
Problem solved.

Thanks for the tip.
0
 
sukumar_diyaCommented:
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
0

Featured Post

Independent Software Vendors: 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