Hey everyone,

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);
Convert.ToInt32(label_Start_Miles1.Text);
Int32.Parse(label_Start_Miles1.Text, out start);

All of them blow up during run, except tryparse which just doesn't work.

Edited 6 Years Ago by Duki: n/a

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.

Thanks for the input. I figured if I was going to add that much code anyways, I would just create a new database query to get the data I needed from the DB instead of the textbox.

int start = Convert.ToInt32(this.vehiclesTableAdapter.QueryStartingMiles(Vehicle_ID));

Thanks for the help.

Definitely the more efficient method :)

As I said, I was just working from what was provided hehe.

This question has already been answered. Start a new discussion instead.