Clyde Eisenbeis wrote:
>
>     using (System.Data.SQLite.SQLiteConnection sqliteConnection = new
> System.Data.SQLite.SQLiteConnection("Data Source=" + stPathFilename +
> ";")) {
>     using (System.Data.SQLite.SQLiteCommand sqliteCmd =
> sqliteConnection.CreateCommand()) {
>     ...
>     sqliteCmd.CommandText = "INSERT INTO ..."
>     ...
>     sqliteCmd.ExecuteNonQuery();
>     sqliteCmd.CommandText = "SELECT last_insert_rowid()";
>     int iKeyID = (int)sqliteCmd.ExecuteScalar();
>
> End up with an exception: "Specified cast is not valid."
>

Changing the type of iKeyID to "long" should make it work, e.g.:

        long iKeyID = (long)sqliteCmd.ExecuteScalar();

Alternatively, you should also be able to use the LastInsertRowId
property of the SQLiteConnection object, e.g.:

        long iKeyID = sqliteConnection.LastInsertRowId;

--
Joe Mistachkin @ https://urn.to/r/mistachkin

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to