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

  • Home
  • SEARCH
  • 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 7748551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:48:53+00:00 2026-06-01T10:48:53+00:00

I am reading data from a table in an SQLite3 database into a ListView

  • 0

I am reading data from a table in an SQLite3 database into a ListView using the code below

At the moment I am limiting the records to display only 200 as displaying all of them takes way too long. (Some 30,000 records)

I would like to give an option to display all the records and if that option is chosen to be able to load every record.

As I said it takes a fair amount of time and I would like to use a progress bar to show the status of it.

I have never used a progress bar before so I don’t know how they work. Would it be the case of adding a few extra lines of code to my code to allow the use of a progress bar or would I have to thread it and use a background worker?

private void cmdReadDatabase_Click(object sender, EventArgs e)
{
    listView4.Columns.Add("Row1", 50);
    listView4.Columns.Add("Row2", 50);
    listView4.Columns.Add("Row3", 50);
    listView4.Columns.Add("Row4", 50);
    listView4.Columns.Add("Row5", 50);
    listView4.Columns.Add("Row6", 50);
    listView4.Columns.Add("Row7", 50);

    try
    {
        string connectionPath = Path.Combine(@"C:\", @"temp\");

        SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder();
        csb.DataSource = Path.Combine(connectionPath, "database.db");

        SQLiteConnection connection = new SQLiteConnection(csb.ConnectionString);
        connection.Open();

        // Query to read the data
        SQLiteCommand command = connection.CreateCommand();
        string query = "SELECT * FROM table_name LIMIT 200 ";
        command.CommandText = query;
        command.ExecuteNonQuery();

        SQLiteDataAdapter dataAdaptor = new SQLiteDataAdapter(command);
        DataSet dataset = new DataSet();
        dataAdaptor.Fill(dataset, "dataset_name");

        // Get the table from the data set
        DataTable datatable = dataset.Tables["dataset_name"];
        listView4.Items.Clear();

        // Display items in the ListView control
        for (int i = 0; i < datatable.Rows.Count; i++)
        {
            DataRow datarow = datatable.Rows[i];
            if (datarow.RowState != DataRowState.Deleted)
            {
                // Define the list items
                ListViewItem lvi = new ListViewItem(datarow["Row1"].ToString());
                lvi.SubItems.Add(datarow["Row2"].ToString());
                lvi.SubItems.Add(datarow["Row3"].ToString());
                lvi.SubItems.Add(datarow["Row4"].ToString());
                lvi.SubItems.Add(datarow["Row5"].ToString());
                lvi.SubItems.Add(datarow["Row6"].ToString());
                lvi.SubItems.Add(datarow["Row7"].ToString());

                // Add the list items to the ListView
                listView4.Items.Add(lvi);
            }
        }
        connection.Close();
    }
    catch(SQLiteException ex)
    {
        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK);
    }
}
  • 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-01T10:48:54+00:00Added an answer on June 1, 2026 at 10:48 am

    Id use a DataView so I can get a count of the records I need using the RowStateFilter. Then iterate through the DataView with a foreach instead of a for statement.

            ProgressBar _Bar = new ProgressBar();
    
            DataView _View = new DataView();
            _View.Table = datatable;
            _View.RowStateFilter = DataViewRowState.CurrentRows;
    
            _Bar.Minimum = 0;
            _Bar.Maximum = _View.ToTable().Rows.Count;
    
            foreach (DataRow datarow in _View.ToTable().Rows)
            {
                // Define the list items    
                ListViewItem lvi = new ListViewItem(datarow["Row1"].ToString());
                lvi.SubItems.Add(datarow["Row2"].ToString());
                lvi.SubItems.Add(datarow["Row3"].ToString());
                lvi.SubItems.Add(datarow["Row4"].ToString());
                lvi.SubItems.Add(datarow["Row5"].ToString());
                lvi.SubItems.Add(datarow["Row6"].ToString());
                lvi.SubItems.Add(datarow["Row7"].ToString());
    
                // Add the list items to the ListView    
                listView4.Items.Add(lvi); 
                _Bar.PerformStep();
            }
    

    The following incraments the progress bar:

    _Bar.PerformStep();
    

    Without running this code I suspect you will have issues with the Progressbar actually updating like you think it will. Your process is running on the UI thread so it will be blocking the UI from updating. You might want to look into running this process on another thread. That is a whole other topic.

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

Sidebar

Related Questions

I'm trying to handle DBNull exception while reading data from database. It's my code:
I'm reading data from a table( from a MySQL Database) with Hibernate SQL Query.
i am reading data from a mysql database table. I have populated a dropdown
C# code is reading data from database through dynamic queries. Select ID, TransDate from
I am reading data from a table and updating into other table in SQLite.
I am reading data from a table using textscan() . The table has 90
I am reading data from multiple serial ports. At present I am using a
I'm reading data from a serial port using an event listener from the SerialPort
I'm reading data from a stream into a char array of a given length,
I'm having some trouble reading data from a file into a vector of Orders.

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.