BIGINT/DECIMAL Datatype conversion issue when getting data from mysql to C#

Posted on 2009-02-08
Last Modified: 2013-12-16
I have a mysql 5.0 database on my machine. I have a table whose primary keys are given the type BIGINT(20). I am using ODBC via a DSN that uses the MySql ODBC driver to connect to mysql.

When I retrieve this data from the database and get it into C#, the datatype is coming across as a DECIMAL. I thought the C# equivalent of a BIGINT datatype was one of the following: long, Int32, Int64. None of these conversions seem to work.

Obviously on my id fields, I do not want decimals. Anyone have some ideas?
public static List<Message> getMessages()


        List<Message> messages = new List<Message>();

        OdbcConnection MyConn = DBConnection.getDBConnection();

        OdbcDataReader result = null;




            OdbcCommand myCmd = new OdbcCommand();

            myCmd.Connection = MyConn;

            myCmd.CommandText = mySqlQueries.getAllMessages;

            result = myCmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (result.Read())


                Message message = new Message();

                String t = result["messageid"].GetType().ToString(); //VALUE IS DECIMAL

                message.MessageId = result.GetInt64(result.GetOrdinal("messageid")); // THIS LINE





Open in new window

Question by:baijajusav
    LVL 14

    Accepted Solution

    have your tried Convert.ToInt64() ?

    however, from a database point of view, do you really need à 64 bit integer ? should a 32 bits integer wouldn't be sufficient ?
    LVL 3

    Author Closing Comment

    That worked! And your right, 32 bits will be plenty. Thanks!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now