Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:07:25+00:00 2026-05-27T22:07:25+00:00

I found several examples of how to get the last inserted row id from

  • 0

I found several examples of how to get the last inserted row id from an sql insert call to my SQLite database, but my script threw this error:

SQLiteException
Message = "SQLite error\r\nnear \")\": syntax error"
InnerException
NULL

Below is the SQL text I sent in and how I used it. Obviously, I misunderstood something. Could someone help me out here?

I am trying to return the ID number that was just inserted.

private static int Save(Dates date, SQLiteConnection con) {
  // REF: http://www.sqlite.org/c3ref/last_insert_rowid.html
  int result = 0;
  string sql = "INSERT INTO Dates1 " +
  "(ID, TaskID, Last1) " +
  "VALUES " +
  "((SELECT MAX(ID) FROM Dates1)+1, @TaskID, @Last); " +
  "SELECT sqlite3_last_insert_rowid(sqlite3*);";
  using (SQLiteCommand cmd = new SQLiteCommand(sql, con)) {
    cmd.Parameters.AddWithValue(Dates.AT_TASK, date.TaskID);
    cmd.Parameters.AddWithValue(Dates.AT_LAST, date.Last.ToShortDateString());
    cmd.CommandText = Dates.SQL_INSERT;
    try {
      result = cmd.ExecuteNonQuery();
    } catch (SQLiteException err) {
      result = -1;
      LogError("Save(Dates, SQLiteConnection)", err);
    }
  }
  return result;
}

FYI: I have set up the table so that ID is supposed to be auto generated using the Create SQL below, but the table only stores -1 for the ID values unless I manually insert it.

public const string SQL_CREATE = "CREATE TABLE Dates1 " +
  "(ID INTEGER PRIMARY KEY AUTOINCREMENT, TaskID INTEGER, Last1 TEXT);";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:07:26+00:00Added an answer on May 27, 2026 at 10:07 pm

    To quote from the SQLite documentation:

    last_insert_rowid() The last_insert_rowid() function returns the ROWID of the last row insert from the database connection which invoked the function. The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function.

    So you need to change your statement to:

    "SELECT last_insert_rowid();"
    

    because what you did was to try and call the C API function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some examples from Microsoft , but I'm not sure how to get
I've found several examples of an inventory database. But I'm looking for someting a
i have found several examples/questions about getting row numbers of the selected cells but
I have tried to get several examples that I have found on here and
I have searched for examples and found several but they are whole large projects.
I have found several examples using datamapper and was able to get them to
I've ran through several examples over the web, and found that every single time
I found several controlsets for that nice looking ribbons (DotNetBar, DivElements, ...), but all
I have a very basic need to get some data from the database and
I found several examples how to use Ext.ux.grid.GridSummary() in GridPanel, main problem here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.