Syntax Question: Reading from MySQL database

I working with a MYSQL database, using C++ .NET. The program compiles, and outputs data to the console, using a line such as this:

Console::WriteLine("{0}", reader->Item[S"age"]);

However, I want to do more than just display the "age" to the console, I want to do calculations on the data. So, how do I convert the infomation to an Integer? I've tried variations of "Int32::Parse", ".ToString", "Int32::ToInt32" etc., but can't get the right syntax.
Please help. Thank You.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

AlexFMConnect With a Mentor Commented:
int n = Int32::Parse(reader->Item[S"age"]->ToString());
KellyJensenAuthor Commented:
AlexFM, thank you for your answer.  It compiles and runs, but after an incredible amount of grinding away, this error message pops up:

Microsoft Development Environment
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll.
Additional information: Input string was not in correct format.

Any other suggestions?
Possibly in most records database field contains valid number in the age field. But some records may contain, for example NULL or other invalid value - you can see this in your current program version. You need to handle exception:

int n;

    n = Int32::Parse(reader->Item[S"age"]->ToString());
catch ( System.FormatException ex )
    // handle error here - for example, show message, set n to 0 etc.
KellyJensenAuthor Commented:
Thank you so very much, there was a glitch in my database. Your answer was very correct.
All Courses

From novice to tech pro — start learning today.