Click here to Skip to main content
15,113,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Guys...

Does anyone of you knows on how to use background worker in loading or populating the data from database using DataReader in VB.NET?
Please help....

here's my code in populating the data:

VB
Public Sub PopulateAudit()
       Dim strSELECT As String = "SELECT * FROM tblsystemaudit " _
             & " WHERE jdate='" & dtpDate.Text & "' " _
             & " AND juser LIKE '" & txtUser.Text & "%' " _
             & " AND jmachine LIKE '" & txtMachine.Text & "%' " _
             & " AND jform LIKE '" & txtForm.Text & "%' " _
             & " AND jaction LIKE '" & txtAction.Text & "%' " _
             & " ORDER BY PK DESC"

       Dim DReader As New DataClassReader
       DReader.strSELECTSQL = strSELECT
       DReader.ReadData()
       dtgView.Rows.Clear()
       Dim a As Integer = 0

       Do While DReader.PinoyLDataReader.Read
           dtgView.Rows.Add()
           With DReader.PinoyLDataReader
               dtgView.Item(0, a).Value = .Item("jdate")
               dtgView.Item(1, a).Value = .Item("jtime")
               dtgView.Item(2, a).Value = .Item("juser")
               dtgView.Item(3, a).Value = .Item("jmachine")
               dtgView.Item(4, a).Value = .Item("jform")
               dtgView.Item(5, a).Value = .Item("jaction")
               dtgView.Item(6, a).Value = .Item("jreference")
               dtgView.Item(7, a).Value = .Item("jcomments")
           End With
           a = a + 1
       Loop
       DReader.PinoyLDataReader.Close()
   End Sub


..now can u tell me how to use the background worker here, where to place it..?

please help me...

thanks in advance guys..
Posted
Updated 27-Jan-21 5:44am
v2

At first you shouldn't use string concatenation to populate your query, because it could cause sql injection so you need parameter queries instead.
And there's really nice sample [^] at the msdn how to use BackgroundWorker.
   
v2
If you want that your dtgView table should add records in background work then you need to user threading for that.

Create one thread and put your PopulateAudit() function into threading process.
Dim myThread As New System.Threading.Thread(AddressOf PopulateAudit)

public sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
mythread.start
end sub 
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900