in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Error on convert db field to int?

Last post 09-01-2010 3:46 PM by cheetah. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-27-2010 3:22 AM

    • delfo
    • Not Ranked
    • Joined on 09-26-2008
    • Posts 1

    Error on convert db field to int?

    Hi, i have this line of code: int? tmp = dr[0] as int?; that assign a db field to a nullable integer variable. But with every integer fields i get always a null value. If i add this line of code after the first one object obj = dr[0]; all works fine and the obj's value is correct. What am i wrong ?? I'm using System.Data.SQLite.DLL Ver 1.0.66 Thanks in advance Stefano
  • 09-01-2010 3:46 PM In reply to

    Re: Error on convert db field to int?

    SQLite returns integer fields as longs most of the time, AFAICT.  Try something like this (assuming dr is a SQLiteDataReader):

    long? tmp = dr.IsDBNull(0) ? (long?)null : dr.GetInt64(0);

    or ...

    int? tmp = dr.IsDBNull(0) ? (int?)null : (int)dr.GetInt64(0);

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems