Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to load data from database using threading and progressbar

How to load data from database using threading and progressbar

Scheduled Pinned Locked Moved C#
databasesql-serversysadminhelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vkuttyp
    wrote on last edited by
    #1

    I want to load data from sql server table to a datagridview using threading and I want to display the loading progress in progressbar. Please help.

    Kutty

    L 1 Reply Last reply
    0
    • V vkuttyp

      I want to load data from sql server table to a datagridview using threading and I want to display the loading progress in progressbar. Please help.

      Kutty

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, typically loading data from a database is a single, atomic, operation, which gets launched, executes, and returns when done; the client simply waits while the server is gathering the requested data. So progress information is simply not available. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      V 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, typically loading data from a database is a single, atomic, operation, which gets launched, executes, and returns when done; the client simply waits while the server is gathering the requested data. So progress information is simply not available. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        V Offline
        V Offline
        vkuttyp
        wrote on last edited by
        #3

        I found a solution during my googling. But it is not working in my case, can any body please check this code. this what I found: public partial class Form1 : Form { public static string ConnectionString = "" //your connection string here DataSet DS = new DataSet(); double TotalRows =0; double RowIndex = 1; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { OleDbConnection DBConn = new OleDbConnection(ConnectionString); OleDbDataAdapter DBAdapter = new OleDbDataAdapter(); DBAdapter.SelectCommand = new OleDbCommand("SELECT Count(*) from tblPersons", DBConn); DBConn.Open(); TotalRows = (int)DBAdapter.SelectCommand.ExecuteScalar(); //retrieve the nr. of rows in the DB Table DBConn.Close(); DBAdapter.SelectCommand.CommandText = "SELECT * from tblPersons"; DS.Tables.Add(new DataTable("Customers")); // Add event handler to the row changing event in the dataset DS.Tables["Customers"].RowChanging += new DataRowChangeEventHandler(Form1_RowChanging); DBAdapter.Fill(DS, "Customers"); dataGridView1.DataSource = DS.Tables[0]; } void Form1_RowChanging(object sender, DataRowChangeEventArgs e) { if (e.Action.ToString() == "Add") //check if the action is 'Add' (not 'Commit') { Thread.Sleep(500); progressBar1.Value = (int)Math.Round((double)(RowIndex / TotalRows) * 100); //update the progressbar progressBar1.Refresh(); RowIndex++; //count rows } } } }

        Kutty

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups