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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:48:52+00:00 2026-06-07T21:48:52+00:00

Needing to store about 20,000 rows of information locally in SQLite Database. There are

  • 0

Needing to store about 20,000 rows of information locally in SQLite Database. There are only two columns containing short text strings, so the actual amount of data is small, but I am struggling to get the rows inserted in under 3-5 minutes on the device. I’ve tried just straight up looping through the dataset and calling a simple WritableDatabase.Insert, but that took a long time. So I did some research and was led to the InsertHelper class where the author sites processing rows at about 900 rows/second (which should put me at 20-30 seconds). I still can’t get the data to process any faster than 3-5 minutes. What am I missing? Does performance vary by device? Using ZTE Optik Android 3.2.1.

public class SqLiteHelper : SQLiteOpenHelper
{
    private const string DATABASE_NAME = "NAME";
    private const int DATABASE_VERSION = 1;
    private readonly Context _context;

    public SqLiteHelper(Context context)
        : base(context, DATABASE_NAME, null, DATABASE_VERSION)
    {
        _context = context;
    }

    public override void OnCreate(SQLiteDatabase db)
    {
        try
        {
            db.ExecSQL("Create Table Inventory (ItemNumber Text Primary Key Not Null, ItemDescription Text);");
        }
        catch (SQLiteException ex)
        {
            Toast.MakeText(_context, ex.Message, ToastLength.Long).Show();
        }
    }

    public override void OnUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
    }
}

class InventoryRepository : AsyncTask
{
    private SqLiteHelper Helper { get; set; }
    private Context Context { get; set; }

    public InventoryRepository(SqLiteHelper helper, Context context)
    {
        Helper = helper;
        Context = context;
    }

    protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
    {
       WS ws = new WS();
       DataTable parts = ws.GetInventory();  //Web service getting inventory items from Server

        Helper.WritableDatabase.Delete("Inventory", null, null);

        DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(Helper.WritableDatabase, "Inventory");

        Helper.WritableDatabase.SetLockingEnabled(false);

        int partColumn = ih.GetColumnIndex("ItemNumber");
        int partDescColumn = ih.GetColumnIndex("ItemDescription");

        Helper.WritableDatabase.BeginTransaction();

        try
        {

            foreach (DataRow part in parts.Rows)
            {
                try
                {
                    ih.PrepareForInsert();

                    ih.Bind(partColumn, part[0].ToString().Replace("'", "''"));
                    ih.Bind(partDescColumn, part[1].ToString().Replace("'", "''"));

                    ih.Execute();
                }
                catch (SQLiteException ex)
                {
                    if (ex.Message.Contains("constraint"))
                        continue;
                    throw;
                }
                catch (NullReferenceException e)
                {
                    continue;
                }
            }
            Helper.WritableDatabase.SetTransactionSuccessful();

        }
        finally
        {
            Helper.WritableDatabase.EndTransaction();
            Helper.WritableDatabase.SetLockingEnabled(true);
            ih.Close();
        }

        return "Done";
    }

    protected override void OnPostExecute(Java.Lang.Object result)
    {
        PreferenceManager.GetDefaultSharedPreferences(Context).Edit().PutString("LastInventoryUpdate", DateTime.Today.ToShortDateString()).Commit();
        Intent intent = new Intent(Context, typeof(Login));
        intent.AddFlags(ActivityFlags.NewTask);
        Context.StartActivity(intent);
    }
}
  • 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-07T21:48:54+00:00Added an answer on June 7, 2026 at 9:48 pm

    Wrap the entire insert loop in a transaction. This will speed things up by an order of magnitude.

    db.beginTransaction();
    try {
        // your insertion loop goes here
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am needing some information on including files in PHP classes. E.G. include Foo2.php;
I'm needing to create a zip file containing documents that exist on the server.
I've been reading about database security when it comes to websites. And it says
I am needing to store easily parsable data in a file as an alternative
I'm needing to store a link structure. As a hierarchy, for example, x link,
I'm needing a fast method to read and store objects with pointers and pointers
Needing some guidance about how to properly graph data that is very small and
What's the recommendation when needing to query an WF4 instance store for a collection
As per this recent question, I'll be needing to store all datetime objects in
I am needing to store a heap of int[] for my levels. I decided

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.