Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2555
  • Last Modified:

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

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

0
baijajusav
Asked:
baijajusav
1 Solution
 
psadacCommented:
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 ?
0
 
baijajusavAuthor Commented:
That worked! And your right, 32 bits will be plenty. Thanks!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now