Input string was not in a correct format

G

Guest

Hi Guys,

I'm trying to retrieve data defined as Numeric in Cache database and display
it in a textbox but it's giving me this error: "Input string was not in a
correct format"


Cheers.
 
R

Robbe Morris [C# MVP]

What .net data type are you to stick this into?

That is a valid string. But would fail in most
..net number oriented data types.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money publishing .NET articles at
http://www.eggheadcafe.com
 
G

Guest

I'm trying to display the value of "item.PercentageUsed" with is a Numeric
form Cache database that looks like this "1999/2000" in a textbox with the
following code:
PercentageUsedTextBox.Text = item.PercentageUsed.ToString();
 
C

Cor Ligthert [MVP]

Badis,

Is this a joke or are you serious. What does that "PercentageUsed" do in
dotNet. I could not find it on MSDN what mostly means that it does not
exist.

Cor
 
G

Guest

"PercentageUsed" is just a property in the "item" class in order to retrieve
the "PercentageUsed" column...
anyway let say I have a column of type 'Numeric' with this format
"1999/2000" could you tell me how can I diplay it in a textbox!!?
because I keep having above error

Thanks
 
J

John B

Badis said:
It looks like this "1999/2000" in Cache database.
Somewhere your program is attempting to convert it to a numeric by using
type.Parse("1999/2000") where type is int|float|decimal|whatever numeric
type.
This will obviously fail as 1999/2000 is not a valid number.
You need to convert the 1999 and 2000 to a numeric value individually
and then do the division.

BTW, it cannot be defined as numeric in the database if that is what you
are getting (unless its a db I havent come across that supports
arithmetic operations as db types, and in that case its not a numeric
type anyway)

HTH

JB
 
B

Ben newsam

Somewhere your program is attempting to convert it to a numeric by using
type.Parse("1999/2000") where type is int|float|decimal|whatever numeric
type.
This will obviously fail as 1999/2000 is not a valid number.
You need to convert the 1999 and 2000 to a numeric value individually
and then do the division.

BTW, it cannot be defined as numeric in the database if that is what you
are getting (unless its a db I havent come across that supports
arithmetic operations as db types, and in that case its not a numeric
type anyway)

Exactly. The db will almost certainly have it as a string, even though
the value in the field is always evaluatable to a number.

People may think that this is a silly thing to want to do, but I
remember being involved in a work-study application some years ago, in
which fields contained things such as "4/7", which stood for "four
days out of seven", and had to be kept in that format rather than the
numerically accurate 0.5714 etc, because it might also contain "8/14"
meaning 8 days per fortnight, which is different although numerically
the same. Such fields were obviously kept as strings and passed
through an evaluator every time they were used. In good old ancient
antique BASIC, this would have been merely EVAL("4/7") or
EVAL("1999/2000"), but in C++ I had to write an entire evaluator to
deal with it.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I think that the percntage of you being mistaken is big :)

what is the "item" class anyway?

the string "1999/2000" will not be evaluated as a number nor in C# not in
any language that support strong typing.

I would be surprised even if VB will do what you expect.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top