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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:22:32+00:00 2026-06-18T03:22:32+00:00

I am trying to execute an SQLiteCommand containing 3 inserts to 3 separate tables.

  • 0

I am trying to execute an SQLiteCommand containing 3 inserts to 3 separate tables. In all 3 tables the primary key is called offset. In the 3rd statement, I want to insert two rows.

There are a total of 11 parameters to the command

Here is the code I used to initialize the command earlier (I want to reuse the command, but this particular problem occurs even on the first use of this statement):

_insertBlockInNewPage = new SQLiteCommand("insert into page(offset) values (?); insert into block(offset, length, originaloffset, page) values (?, ?, ?, ?); insert into chunk(offset, length, page, free) values (?, ?, ?, 0), (?, ?, ?, 1)", _db);
for (var i = 0; i < 11; i++) _insertBlockInNewPage.Parameters.Add(new SQLiteParameter(DbType.Int64));
_insertBlockInNewPage.Prepare();

And here is the method that will use this command:

public void InsertBlockInNewPage(long offset, long length, long originalOffset, long pageLength)
{
    _insertBlockInNewPage.Parameters[0].Value = offset;
    _insertBlockInNewPage.Parameters[1].Value = offset;
    _insertBlockInNewPage.Parameters[2].Value = length;
    _insertBlockInNewPage.Parameters[3].Value = originalOffset;
    _insertBlockInNewPage.Parameters[4].Value = offset;
    _insertBlockInNewPage.Parameters[5].Value = offset;
    _insertBlockInNewPage.Parameters[6].Value = length;
    _insertBlockInNewPage.Parameters[7].Value = offset;
    _insertBlockInNewPage.Parameters[8].Value = offset + length;
    _insertBlockInNewPage.Parameters[9].Value = pageLength - length;
    _insertBlockInNewPage.Parameters[10].Value = offset;
    _insertBlockInNewPage.ExecuteNonQuery();
}

What is important here that parameter 5 has the value 0 and parameter 8 has the value 131072 (i.e. not the same). When I execute this command it throws an Exception telling me that the primary key must be unique.

What’s weird is that if I only insert one row in the chunk table it works. What’s weirder is if I execute the insert of the chunk table in a separate SQLiteCommand, but still inserting 2 rows simultaneously it works too. So i’m guessing I must have done something wrong with the parameters. But I really cannot see anything wrong with this code. Can anyone help me with this?

  • 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-18T03:22:34+00:00Added an answer on June 18, 2026 at 3:22 am

    In SQLite, parameter indexes are counted from the start of the SQL statement.

    This implies that it is not possible to use unnamed parameters together with multiple SQL commands in one SQLCommand.

    You could try to use numbered parameters:

    insert into page(offset) values (?1);
    insert into block(offset, length, originaloffset, page) values (?2, ?3, ?4, ?5);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to execute this statement in a rails migration to generate a multi column
When I am trying to execute this sql statement, I am getting exception as-
I'm trying to execute JavaScript functions that are called when a event (for example
I'm trying execute the DataTable example avaiable on Primefaces Showcase . All functions works
When trying to execute a statement on Oracle RDBMS I always get OCI_INVALID_HANDLE as
When I am trying to execute INSERT statement in oracle, I got SQL Error:
Trying to execute powershell script in my C# code. Using .NET Framework v. 4.0.30319
Im trying to execute a .bat file remotely in a powershell script. The code
While trying to execute the following lines only the last two statements are displayed(Here
I`m trying to execute a shell command with arguments in C# , and The

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.