SQLite.Net-PCL
SQLite.Net-PCL copied to clipboard
Can't read object from ExecuteScalar method
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);