473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problem converting DB variable to double in C#

Hello everyone,

I'm having some trouble with a variable from a database. That variable in that database is of type double.

To read from the database, I'm using a variable dr of type OleDbDataReader.

So far, I've been using dr["variablename"].ToString() to work with the variables from this database - without the ToString part it wasn't working.

However, with this specific variable (I'll call it "var"), I have to do numerical comparisons of >= and <=, so obviously, just using dr["var"].ToString() doesn't work.
Therefore, I tried creating a variable of type double called varConv and setting it as varConv = Convert.ToDouble(drPen["var"].ToString()). That doesn't work, gives me an error message saying "Input string was not in a correct format". If I remove the ToString part, it also doesn't work, with a different error message saying "Object cannot be cast from DBNull to other types".
Trying to do a direct comparison, as in dr["var"] >= x also doesn't work, says "Operator '>=' cannot be applied to operands of type 'object' and 'int' ".

I'm out of ideas... All help is appreciated! Thanks in advance!
Aug 22 '12 #1

✓ answered by Rabbit

Sounds like you have nulls in your data. Change the nulls to something else in your query, a 0 or something.

3 1814
Rabbit
12,516 Expert Mod 8TB
Sounds like you have nulls in your data. Change the nulls to something else in your query, a 0 or something.
Aug 23 '12 #2
Geez... I thought there were no null values inside the DB, but there were... That was causing the problem. Guess I could have avoided this problem by paying more attention to the values in the DB. =/
Problem solved. Thanks!
Aug 23 '12 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Aug 23 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Julián Albo | last post by:
Hello. This test: #include <stdio.h> int main () { double a= -1.0e-120; if (a < 0.0)
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
1
by: H. Kaya | last post by:
Hallo, I have a problem converting a XML file to a other. I have no idea how I can do this. I try it for a long time but I can not find a solution. Has anyone a Idea? Below you can find my...
1
by: Kent Lewandowski | last post by:
Hi, I saw this post from 3 years ago regarding converting DOUBLE values to CHAR in ibm DB2. Now I'm having the same problem. No real solution was posted to that old thread. Has anyone got...
3
by: Caesar Augustus | last post by:
Hello Tom, Long time listener, first time caller... I have been working with vb code to automate a salary increase process that not only rounds to the nearest penny but also rounds to the...
20
by: Ollie | last post by:
Ok, As the Convert.ToDateTime has not been implimented yet, how do I convert a double to datetime??? I have looked all over with no luck at all. Please help me!
2
by: D. Shane Fowlkes | last post by:
Here's a good one. I've been using an Excel spreadsheet for the past couple of years to calculate a file's Estimated Download Time based off of a solid 50kbs connection (dial up). This is for a...
1
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList...
4
by: Jeff | last post by:
Hey ..NET 2.0 In my code am I trying to convert an int value into a decimal: decimal d = 0; int k = 87664; d = Convert.ToDecimal(k/100);
2
by: clintonb | last post by:
Victor said: The double value that I'm trying to convert to GCSMoney (which is implemented as cents) was produced by multiplying a dollar amount by an interest rate to get interest. double...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.