Connecting Tech Pros Worldwide Help | Site Map

string to double

Newbie
 
Join Date: Aug 2009
Posts: 4
#1: Aug 13 '09
I created an application in vb.net 2005. It works fine on my machine. I tested several different test machines and all were working fine. As for the client, it's generating an error. My application reads from an excel sheet and imports the values to an oracle database. the error being generated is: "conversion from type string to type double is not valid". Why is it generating only on the client's computer and not mine?
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 274
#2: Aug 13 '09

re: string to double


Quote:

Originally Posted by dandalero View Post

My application reads from an excel sheet and imports the values to an oracle database.

Can you post the code that does this?

Steven
Newbie
 
Join Date: Aug 2009
Posts: 4
#3: Aug 13 '09

re: string to double


Dim deci As Decimal = 0
deci = CDec(dt.Rows(i).Item(13))

If Not IsDBNull(dt.Rows(i).Item(13)) AndAlso deci > 0 Then
.price = CDec(dt.Rows(i).Item(13))
End If

POITEM.price = .price
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 274
#4: Aug 13 '09

re: string to double


Could it have something to do with the regional settings on the machines? This often creates a difference between e.g. 0,13 and 0.13.

Steven
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#5: Aug 13 '09

re: string to double


Are you testing with the same test materials?
Spreadsheet Alpha works just fine on your machine and your other test machines but spreadsheet Bravo fails at the client. Could indicate that spreadsheet Bravo is not set up the same as the test subject they gave you and that you are not checking for the possibility that a value might not be right.
Quote:
deci = CDec(dt.Rows(i).Item(13))
This can only work if the cell actually has a number. What if it doesn't? When coding you have to account for the possibility that the world is not perfect. Wrap it in a try/catch for starters and work your way out from there. MessageBox with error statement in the catch construct might help.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#6: Aug 13 '09

re: string to double


When this type of error pops up, its almost always a regional thing. Differences between , and . and whatnot. Need to specify the correct region/culture for the data being parsed, and not just the default region/culture

I also recomend using the .NET conversions instead of the old VB conversions:
Double.Parse() or Double.TryParse()
Newbie
 
Join Date: Aug 2009
Posts: 4
#7: Aug 14 '09

re: string to double


Regarding the regional settings, I checked both regional settings and they are exactly the same. As for the cell having a number, i checked the excel sheet and didn't find any null or empty values.
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 274
#8: Aug 14 '09

re: string to double


Did you also check for non-numerical values? When there is a letter or a special character in the cell it also cannot be converted to double.

Steven
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#9: Aug 14 '09

re: string to double


Perhaps you should be checking the object type first:
dt.Rows(i).Item(13).GetType().ToString()
Make sure its what you think it should be (every time)
Then check that:
dt.Rows(i).Item(13).ToString()
is always something that can be parsed into a double?
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 274
#10: Aug 14 '09

re: string to double


Or just check if it is numeric. If not, it can't be parsed into a double:

Expand|Select|Wrap|Line Numbers
  1. If IsNumeric(dt.Rows(i).Item(13).ToString())
Steven
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#11: Aug 14 '09

re: string to double


Quote:

Originally Posted by dandalero View Post

Regarding the regional settings, I checked both regional settings and they are exactly the same. As for the cell having a number, i checked the excel sheet and didn't find any null or empty values.

But did you actually take anyone's advice? Put in some try/catch blocks in case something is not as it appears? Put in some 'if' conditionals to only do what you want 'if' the values were as expected? Put up some messageboxs or log files to report problems?
Newbie
 
Join Date: Aug 2009
Posts: 4
#12: Aug 17 '09

re: string to double


I placed some Try/Catch blocks and managed to find out in which column in the excel sheet the error was being generated. I checked the whole column but i saw no letters or special characters there. But once again, if the column contained letters or empty value, shouldn't it generate an error on any computer??? This error is only being generated on one computer.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#13: Aug 17 '09

re: string to double


Just because you don't see it, doesn't mean its not there. There are a lot of characters that are not displayable. Control codes for example.

Quote:
This error is only being generated on one computer.
So far.

Quote:
But once again, if the column contained letters or empty value, shouldn't it generate an error on any computer???
There is a setting on that machine that is different than the other machines.
Format of a date... country regionalization... time format... thousands seperator character... Version of Excel on that one machine... something
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#14: Aug 17 '09

re: string to double


Quote:

Originally Posted by tlhintoq View Post

Version of Excel on that one machine... something

Ooo that's a good one, a different version of office would also have different versions of Jet. I would go so far as to say a difference in office updates on one vs the other could cause troubles.
Reply