Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

VS 2008 VB 2008 Backgroundworker with datagridview on unbound data

$
0
0
Hi,
I have the following code in my vb application, but duo to large amount of data the program stuck, so i need to make it in a background worker,i'v tried all the tutorials from the web but no luck, can anyone please help me with this one.
I will appreciate very very much. Thx in advance.

Code:

DataGridView1.Rows.Clear()
        Dim connection As New MySql.Data.MySqlClient.MySqlConnection
        Dim comand As New MySql.Data.MySqlClient.MySqlCommand()
        Dim adaptor As New MySql.Data.MySqlClient.MySqlDataAdapter
        Dim dataset As New DataSet
        Dim myReader As MySql.Data.MySqlClient.MySqlDataReader

        connection.ConnectionString = My.MySettings.Default.gazeConnectionString
        connection.Open()

        ' Se incarca date iscir
        comand.CommandText = "SELECT * FROM iscir WHERE `tip_document` = 'PT-A1' ORDER BY STR_TO_DATE(data_expirare_document,'%d.%m.%Y') ASC"

        comand.Connection = connection
        adaptor.SelectCommand = comand
        myReader = comand.ExecuteReader

        'arata ISCIR
        While myReader.Read
            Dim ro As String() = New String() {myReader.GetString(0), myReader.GetString(6), myReader.GetString(5), myReader.GetString(4), myReader.GetString(2)}
            DataGridView1.Rows.Add(ro)
        End While
        myReader.Close()


        'arata aparat
        Dim tot1 As Integer
        Dim randuri1 = DataGridView1.Rows.Count.ToString
        For tot1 = 0 To randuri1 - 1
            Dim cod = DataGridView1.Item(1, tot1).Value
            comand.CommandText = "SELECT * FROM aparat WHERE id = '" & cod & "'"
            comand.Connection = connection
            adaptor.SelectCommand = comand
            myReader = comand.ExecuteReader
            While myReader.Read
                DataGridView1.Rows.Item(tot1).Cells(19).Value = myReader.GetString(3)
                DataGridView1.Rows.Item(tot1).Cells(20).Value = myReader.GetString(4)
                DataGridView1.Rows.Item(tot1).Cells(21).Value = myReader.GetString(5)
                DataGridView1.Rows.Item(tot1).Cells(22).Value = myReader.GetString(7)
                DataGridView1.Rows.Item(tot1).Cells(23).Value = myReader.GetString(6)
            End While
            myReader.Close()
        Next tot1

        ' arata client
        Dim tot As Integer
        Dim randuri = DataGridView1.Rows.Count.ToString
        For tot = 0 To randuri - 1
            Dim aparat = DataGridView1.Item(1, tot).Value

            comand.CommandText = "SELECT * FROM aparat WHERE (id = '" & aparat & "' );"
            dataset = New DataSet()
            comand.Connection = connection
            adaptor.SelectCommand = comand
            adaptor.Fill(dataset, "dialog")
            Dim client = dataset.Tables("dialog").Rows(0).Item(26)

            comand.CommandText = "SELECT * FROM clienti WHERE id = '" & client & "'"
            comand.Connection = connection
            adaptor.SelectCommand = comand
            myReader = comand.ExecuteReader
            While myReader.Read
                DataGridView1.Rows.Item(tot).Cells(7).Value = myReader.GetString(1)
                DataGridView1.Rows.Item(tot).Cells(8).Value = myReader.GetString(2)
                DataGridView1.Rows.Item(tot).Cells(9).Value = myReader.GetString(3)
                DataGridView1.Rows.Item(tot).Cells(10).Value = myReader.GetString(4)
                DataGridView1.Rows.Item(tot).Cells(11).Value = myReader.GetString(5)
                DataGridView1.Rows.Item(tot).Cells(12).Value = myReader.GetString(6)
                DataGridView1.Rows.Item(tot).Cells(13).Value = myReader.GetString(7)
                DataGridView1.Rows.Item(tot).Cells(14).Value = myReader.GetString(8)
                DataGridView1.Rows.Item(tot).Cells(15).Value = myReader.GetString(9)
                DataGridView1.Rows.Item(tot).Cells(16).Value = myReader.GetString(10)
                DataGridView1.Rows.Item(tot).Cells(17).Value = myReader.GetString(12)
                DataGridView1.Rows.Item(tot).Cells(18).Value = myReader.GetString(13)
            End While
            myReader.Close()
        Next tot

        'arata iscir
        Dim tot2 As Integer
        Dim randuri2 = DataGridView1.Rows.Count.ToString
        For tot2 = 0 To randuri2 - 1
            Dim cod = DataGridView1.Item(0, tot2).Value
            comand.CommandText = "SELECT * FROM iscir_pta1 WHERE id_aparat = '" & cod & "'"
            comand.Connection = connection
            adaptor.SelectCommand = comand
            myReader = comand.ExecuteReader
            While myReader.Read
                DataGridView1.Rows.Item(tot2).Cells(5).Value = myReader.GetString(4)
                DataGridView1.Rows.Item(tot2).Cells(6).Value = myReader.GetString(5)
                DataGridView1.Rows.Item(tot2).Cells(24).Value = myReader.GetString(92)
                DataGridView1.Rows.Item(tot2).Cells(25).Value = myReader.GetString(94)
            End While
            myReader.Close()
        Next tot2


Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>