How to Fill DataSet & Bind DataGridView in Different Threads

The advantage of Microsoft Windows threading is the ability to separate your processes, so one process does not interfere with another, speeding up your application. One type of threading is loading a DataSet and a DataGridView's DataSource property in a separate thread, so your user interface does not pause during execution. You first create a thread and use the thread to load the data.

Instructions

    • 1

      Open Visual Studio from the Windows "Start" menu. Open your Web project and load the file you want to use to fill the DataSet and DataGridView.

    • 2

      Create the thread. You must define the function you use to fill the DataSet and DataGridView when you create the thread. When the thread is created, these functions load into the thread. The following code shows you how to create a thread and point the thread to the "FillData" function:

      Dim fill As Thread
      Dim fill As New ThreadStart(AddressOf FillData)

    • 3

      Define the "FillData" function. The following code creates the function you use to encompass your data processes to fill the DataSet and DataGridView:

      Public Sub FillData()
      End Sub

    • 4

      Add the function code to query the data, fill the DataSet and bind the data to the GridView. Place the following code within the function definition you created in step three:

      connect.Open()
      Dim query As New SqlCommand("select * from customers", connect)
      da = New SqlDataAdapter(query)
      da.Fill(dataset, "NewTable")
      gridView.DataSource = dataset

      Replace the query in the "SqlCommand" object with your own.

Related Searches:

References

Comments

Related Ads

Featured