Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Syntax Question: Reading from MySQL database

Posted on 2004-11-01
Medium Priority
Last Modified: 2010-04-24
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.
Question by:KellyJensen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 48

Accepted Solution

AlexFM earned 500 total points
ID: 12470625
int n = Int32::Parse(reader->Item[S"age"]->ToString());

Author Comment

ID: 12470845
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?
LVL 48

Expert Comment

ID: 12470909
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.

Author Comment

ID: 12476568
Thank you so very much, there was a glitch in my database. Your answer was very correct.

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question