FWIW, .TryParse simply does the try/catch for the programmer
No it doesn't. When you use TryParse there is no exception generated (even 'behind the scenes'). You don't pay the overhead of generating and catching an exception if the input is not in the correct format.
Alright so the Try Catch did work but now I am having a new issue. Basically if the textbox is pre-populated and I erase it, I want it to revert to the value in the Parent Cell instead it is reverting to the value that was previously populated in the textbox.
When I tracked back to my inital error in the line
the str value was the value in the parent cell although it wasn't empty it was in the format 60,00 Kd which is the right value but I am guessing it was having trouble converting the commas into a decimal and inserting it in to the database along with the
currency word which the trim should be taking care of but it isn't. Any ideas?
Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
</div> </div>
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
No it's not. You cannot have 'kd' in a double. A double is made up of an optional sign character, thousands separator, digits and decimal place. They have to be in the right order and conform to the locale. The letters 'kd' are not allowed.
Paul Linton
Star
13405 Points
2532 Posts
Re: Input String Is Not In A Correct Format - Help!
Apr 13, 2012 12:04 AM|LINK
No it doesn't. When you use TryParse there is no exception generated (even 'behind the scenes'). You don't pay the overhead of generating and catching an exception if the input is not in the correct format.
rankone
Member
53 Points
53 Posts
Re: Input String Is Not In A Correct Format - Help!
Apr 13, 2012 03:15 PM|LINK
Alright so the Try Catch did work but now I am having a new issue. Basically if the textbox is pre-populated and I erase it, I want it to revert to the value in the Parent Cell instead it is reverting to the value that was previously populated in the textbox. When I tracked back to my inital error in the line
the str value was the value in the parent cell although it wasn't empty it was in the format 60,00 Kd which is the right value but I am guessing it was having trouble converting the commas into a decimal and inserting it in to the database along with the currency word which the trim should be taking care of but it isn't. Any ideas?
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Input String Is Not In A Correct Format - Help!
Apr 13, 2012 11:52 PM|LINK
@ rankone
look at the culture specific form of .TryParse:
http://msdn.microsoft.com/en-us/library/3s27fasw.aspx "Double.TryParse Method (String, NumberStyles, IFormatProvider, Double%)"
<div> <div class="summary">Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
</div> </div>g.
rankone
Member
53 Points
53 Posts
Re: Input String Is Not In A Correct Format - Help!
Apr 16, 2012 05:40 PM|LINK
I tried this and I still get the input string error
string str = ((TableCell)((TableRow)tb.Parent.Parent).Cells[((TableRow)tb.Parent.Parent).Cells.GetCellIndex((TableCell)tb.Parent) - 1]).Text.Replace("Kd", "").Trim(); double str2 = double.Parse(str, new CultureInfo("da-Dk")); Data.SetPrice(store, item, Convert.ToDouble(str2));The debugger suggests that the str value is 61,00 kd which is the right value but it isn't being able to convert the str value to a double.
Any ideas?
Paul Linton
Star
13405 Points
2532 Posts
Re: Input String Is Not In A Correct Format - Help!
Apr 16, 2012 10:47 PM|LINK