Click here to Skip to main content
15,887,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am getting the error input string not in correct format.
C#
Tusd = decimal.Parse(drTExp.GetValue(0).ToString());

Please can someone help me.

Thanks


Regards

Suman
Posted
Updated 14-May-14 2:10am
v2
Comments
lukeer 14-May-14 8:03am    
Obviously, drTExp is nothing that can be interpreted as decimal. What exactly is its value?
Prasad Avunoori 14-May-14 8:03am    
May be it is other than Decimal.
Wessel Beulink 14-May-14 8:07am    
what is Tusd for variable?
babli3 14-May-14 8:09am    
it is decimal
CHill60 14-May-14 8:12am    
What is the value of drTExp.GetValue(0) ?

1 solution

C#
Tusd = decimal.Parse(drTExp.GetValue(0).ToString());


Here You are getting this error because when compiler try to convert drTExp.GetValue(0).ToString() to decimal its getting wrong string format.
This happens when your string is empty or null or its not containing any decimal value.

Here you can avoid this by checking for the string before you do the conversation.And use Convert.ToString() instead of .ToString()

C#
Tusd =  !string.IsNullOrEmpty(Convert.ToString(drTExp.GetValue(0))) 
        ? 
        decimal.Parse(Convert.ToString(drTExp.GetValue(0))) 
        :
        0;
 
Share this answer
 
v2
Comments
babli3 14-May-14 8:58am    
Thanks alot
lukeer 15-May-14 4:33am    
I agree with the "test before parse" part. But why should OP use Convert.ToString() instead of .ToString()?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900