I have a label that gets data from a database and uses that as the .Text field. I want to compare this .Text field with an integer value, but I can't convert the text. The value I'm trying to convert to integer is "25,000". Here's what I've tried:
Int32.TryParse(label_Start_Miles1.Text, System.Globalization.NumberStyles.Integer, null, out start);
Int32.Parse(label_Start_Miles1.Text, out start);
All of them blow up during run, except tryparse which just doesn't work.
The problem is the "," within the number I believe.
A messy workaround (because I am sleepy due to the excessive heat here atm) would be the following:
string labelSplit = label_Start_Miles1.Text.Split(',');
string labelNew = "";
for (int a = 0; a < labelSplit.Length; a++)
labelNew += labelSplit[a];
int32 newInt = Convert.ToInt32(labelNew);
That might work for you, at least I hope it does :) it should pull out all the commas in your numeric value allowing it to be converted. The only problem you might have from there is the decimal value, if there's anything to the right of the decimal it may want you to be using double or decimal instead of int.
Hope this helps :) Please mark as solved if it resolves your issue.