c# - When i select from sqlite column of type 'int' I can cast to .net int but when I select from 'integer' column I cannot -
i'm using system.data.sqlite, selecting sqlite database table column has type 'integer', , when this:
int x = (int)reader["mycolumn"];
it fails. problem not value null; column not nullable. if change data type of column 'int' works fine. values in column '2', '3', '4', etc.; nothing big.
anyone know if expected behaviour?
as other answerer mentioned, sqlite integer stored in 1, 2, 3, 4, 6, or 8 bytes. however, won't overflow or out of range exceptions.
in context, (int)
cast, not conversion. if reader[]
didn't return object of type integer, if it's returning different numeric type, cast exception, regardless of value contains.
based on range of valid values sqlite integer, i'd guess it's returning value 64-bit integer, long
. verify, try this:
object x = reader["mycolumn"]; debug.writeline(x.gettype().name);
Comments
Post a Comment