Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 16, 2012 10:47 PM by Paul Linton
Apr 13, 2012 12:04 AM|LINK
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.
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
Data.SetPrice(store, item, Convert.ToDouble(str));
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?
Apr 13, 2012 11:52 PM|LINK
look at the culture specific form of .TryParse:
http://msdn.microsoft.com/en-us/library/3s27fasw.aspx "Double.TryParse Method (String, NumberStyles, IFormatProvider, Double%)"
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.
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.
Apr 16, 2012 10:47 PM|LINK
61,00 kd which is the right value