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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:29:08+00:00 2026-05-12T09:29:08+00:00

Currently, I am trying to fill an SQLite database with tens of thousands of

  • 0

Currently, I am trying to fill an SQLite database with tens of thousands of text data using this this method:

SQLiteConnection = new SQLiteConnection(cntnStr);
connection.Open();

foreach(Page p in pages)
{
     using (SQLiteCommand command = new SQLiteCommand(String.Format("Insert Into Pages (ID, Data, Name) Values ({0}, '{1}', '{2}')", id, p.Data, p.Name), connection))
         command.ExecuteNonQuery();
}

However, I suspect that doing this about 10 times per second is probably slowing the whole process down. Is there a way I can collate the data in memory and then add every 5000 records or so into the database in batch (so it is faster)?

EDIT: Super-important: Make sure you perform all your SQL commands within a DbTransaction – in this case an SQLiteTransaction:

SQLiteTransaction trans = connection.BeginTransaction();

// SQL centric code - repeated inserts/changes

trans.Commit(); // adds your changes

It improves performance by 1000x.

  • 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-12T09:29:09+00:00Added an answer on May 12, 2026 at 9:29 am

    Use a parameterized query, instead of building the query using string concatenation :

    using (SQLiteConnection = new SQLiteConnection(cntnStr))
    {
        connection.Open();
    
        string query = "Insert Into Pages (ID, Data, Name) Values (?, ?, ?)";
        using (SQLiteCommand command = new SQLiteCommand(query, connection)
        {
            command.Parameters.Add("id", DbType.Int32);
            command.Parameters.Add("data", DbType.String);
            command.Parameters.Add("name", DbType.String);
            foreach(Page p in pages)
            {
                 command.Parameters["id"].Value = p.Id;
                 command.Parameters["data"].Value = p.Data;
                 command.Parameters["name"].Value = p.Name;
                 command.ExecuteNonQuery();
            }
        }
    }
    

    This will be faster because the DbCommand is only created once, and the query is only parsed once. Also, you avoid the risks of SQL injection due to the string concatenation

    BTW, have a look at this article by Robert Simpson (author of the SQLite .NET provider)

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

Sidebar

Related Questions

I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I'm currently trying to get the most popular productID from my MSSQL Database. This
I am currently trying to use an SQLite database with a DataGridView in C#.
I am trying to auto fill a form (currently using contact form 7) with
Currently, I'm trying to fill a dictionary in Python but I think what I'm
I'm currently trying out Aptana Studio 3 for PHP development (I'm pretty new to
I'm currently trying to create a database on eclipse. The user will be able
I'm currently trying to create a database on eclipse. The user will be able
I'm currently trying to set up integration/acceptance testing for a new rails 3 application
I am trying to fill a livecycle created form with form data from django.

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.