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 9036761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:04:50+00:00 2026-06-16T09:04:50+00:00

I am using http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki version 1.0.82.0 When I insert a row like so: INSERT

  • 0

I am using http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki version 1.0.82.0

When I insert a row like so:

"INSERT INTO [testtable] (col1,col2) values ('','')"

I always get a result of 1 from SQLiteCommand.ExecuteNonQuery(); where it should be returning 0 (OK) or 101 (DONE). I know the row is getting inserted just fine because the auto increment value increases each time I run the method.

The class

readonly object _threadlock = new object();
readonly string _file;

public CSQLite(string file)
{
    _file = file;
}

private SQLiteConnection _sqlCon;
private SQLiteCommand _sqlCmd;
private SQLiteDataAdapter _db;

private void SetConnection()
{
    lock (_threadlock)
    {
        _sqlCon = new SQLiteConnection(String.Format("Data Source={0};Version=3;New=False;Compress=True;", _file));
    }
}

public int SimpleInsertAndGetlastID(out int id)
{
    lock (_threadlock)
    {
        SetConnection();
        _sqlCon.Open();

        //Execute
        _sqlCmd = _sqlCon.CreateCommand();
        _sqlCmd.CommandText = "INSERT INTO [testtable] (col1,col2) values ('','')";
        var res = _sqlCmd.ExecuteNonQuery();

        //Get id
        _db = new SQLiteDataAdapter("select last_insert_rowid();", _sqlCon);
        var ds = new DataSet();
        _db.Fill(ds);
        DataTable dt = ds.Tables[0];
        var val = dt.Rows[0][0].ToString();

        Int32.TryParse(val, out id);

        _sqlCon.Close();
        return res;
    }
}

The Test:

/// <summary>
///A test for SimpleInsertAndGetlastID
///</summary>
[TestMethod()]
public void SimpleInsertAndGetlastIDTest()
{
    var file = "dbs\\test.db";
    var target = new CSQLite(file);
    var id = -1;
    var res = -1;

    try
    {
        res = target.SimpleInsertAndGetlastID(out id);
    }
    catch (Exception ex){/*Breakpoint*/}

    Assert.IsTrue(id > 0); //id gets +1 every time the test is run so the row *is* getting inserted
    Assert.IsTrue(res==0||res==101); //Res is always 1 for some reason
}

Table creation (in case that’s the problem):

public List<string> Columns { get; set; }

if (!File.Exists(_dbFile))
    SQLiteConnection.CreateFile(_dbFile);

var fieldqry = "";
var count = 0;
Columns.ForEach((field) =>
    {
        count++;

        fieldqry += String.Format("[{0}] TEXT NULL", field);

        if (count < Columns.Count)
            fieldqry += ",";
    });

var qry = String.Format("CREATE TABLE IF NOT EXISTS [{0}](" +
                        "[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," +
                        "{1}" +
                        ");", TableName, fieldqry);

var sql = new CSQLite(_dbFile);
var res = sql.Execute(qry);
if(res!=SqLiteErrorCodes.SQLITE_OK)
    throw new SqLiteImplementationException("Query failed.");

Where columns is new List<string> { "col1", "col2" } };

Can anyone tell me what I did wrong?

  • 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-06-16T09:04:51+00:00Added an answer on June 16, 2026 at 9:04 am

    ExecuteNonQuery() does not return a SQLite error code, it returns the number of rows affected by the query. If you are inserting a row, 1 sounds like the expected result if the operation was successful.

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

Sidebar

Related Questions

There are Windows dll's here: http://www.sqlite.org/download.html There are .NET setups here: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki If I'm
I have this web service : using System.Web.Services; namespace Contracts { [WebService(Namespace = http://tempuri.org/)]
I am reading here: http://groovy.codehaus.org/modules/http-builder/doc/get.html I seem to be able to get i) XMLSlurper
Database : SQLite Column : SomeTable.Logged (DateTime) Im using the System.Data.SQLite component. I save
I'm trying to build System.Data.SQLite in Visual Studio using the source code downloaded from
I'm using http://hackage.haskell.org/package/sqlite-0.5.2.2 for binding to SQLite database. Inside *.db file there is text
Using techniques as hinted at in: http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.callbackcontract.aspx I am implementing a ServerPush setup for
From http://csharpindepth.com/Articles/Chapter8/PropertiesMatter.aspx using System; struct MutableStruct { public int Value { get; set; }
Im using http://www.ashberg.de/php-barcode/ scripts to generate a barcode. I now need to import the
I'm using http://keith-wood.name/countdown.html . Each 'Event' table in my database has a 'date' column.

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.