We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

Medium Priority
2,808 Views
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;
        try
        {            
            MyConn.Open();
            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
               //ERRORS
           .
           .
           .

Open in new window

Comment
Watch Question

Commented:
have your tried Convert.ToInt64() ?

http://msdn.microsoft.com/en-us/library/system.convert.toint64.aspx

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That worked! And your right, 32 bits will be plenty. Thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.