SQLite.Net-PCL icon indicating copy to clipboard operation
SQLite.Net-PCL copied to clipboard

Can't read object from ExecuteScalar method

Open SlyNet opened this issue 8 years ago • 0 comments

The following code sqLiteCommand.ExecuteScalar<object>(); throws an exception:

<System.NotSupportedException: Don't know how to read System.Object
   at SQLite.SQLiteCommand.ReadCol(sqlite3_stmt stmt, Int32 index, ColType type, Type clrType)
   at SQLite.SQLiteCommand.ExecuteScalar[T]()

if returned value from query is int

The workaround is to use

    var scalarValue = sqLiteCommand.ExecuteScalar<string>();
    int value = scalarValue == null ? 0 : Convert.ToInt32(scalarValue);

SlyNet avatar Sep 13 '16 07:09 SlyNet