in

System.Data.SQLite

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

Get last insert ID

Last post 10-12-2006 2:12 PM by xhenxhe. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-06-2005 9:18 PM

    Get last insert ID

    Maybe im just braindead but the following does not work:
    // create a connection & insert command
            SQLiteCommand IDCmd = new SQLiteCommand("Select sqlite_last_insert_rowid();", conn);
           
            try {
                conn.Open();
                cmd.ExecuteNonQuery();
                p.PrimaryKey = IDCmd.ExecuteScalar();
            }
            finally {
                conn.Close();
                conn.Dispose();
            }

    it throws an error:
    System.Data.SQLite.SQLiteException: SQLite error
    no such function: sqlite_last_insert_rowid

    on the line highlighted in red.  what exactly am I doing wrong?
  • 12-06-2005 10:12 PM In reply to

    Re: Get last insert ID

    Try SELECT last_insert_rowid(); instead :)

    Robert

     

  • 12-21-2005 12:25 PM In reply to

    Re: Get last insert ID

    doh!  I figured this out about 5 minutes later and forgot to say I did.
  • 10-12-2006 2:11 PM In reply to

    Re: Get last insert ID

    Just a guess, but try

    SQLiteCommand IDCmd = new SQLiteCommand("Select last_insert_rowid();", conn);
  • 10-12-2006 2:12 PM In reply to

    Re: Get last insert ID

    Oops. I only saw the first post, not the entire thread....
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems