vb.net form with a progress bar

using vb.net 2005, I have a form with a progress bar on it, and I want to have the bar update each time it completes a record.

I can have up to 50,000 for this form to process, but I want it to also update a label field on the form, so that I know what record count it is currently on.

Right a few things is not working out for me

1. I can't get the label to update.
2. When I run this app and open another window on top of it, the form does not refresh for me with the current contents of the form.

I am new to doing windows development with .net, so any help on this would be appreciated.

Dim cmdCommand As SqlClient.SqlCommand
        Dim daDataAdapter As SqlClient.SqlDataAdapter
        Dim dsDstData As Data.DataSet
        Dim dtDataTable As Data.DataTable
        Dim strStoredProcName As String = "Proc_Adwords_GetKeywordUrlList"
        Dim strURL As String = ""
        Dim objWebRequest As System.Net.HttpWebRequest
        Dim objWebResponse As System.Net.HttpWebResponse
        Dim streamReader As System.IO.StreamReader
        Dim strHTML As String
        Dim strDbConn As String = "MYFBCONN"

        

        'Create the sql connection command object
        cmdCommand = New SqlClient.SqlCommand

        Dim objConnection As New SqlConnection(strDbConn)

        Try
            objConnection.Open()
            With cmdCommand
                daDataAdapter = New SqlClient.SqlDataAdapter
                'Set the command text to the value of the query
                .CommandText = strStoredProcName
                'Set the command type to text for sql query passed into the function
                .CommandType = CommandType.StoredProcedure
                'Set the command object database connection
                .Connection = objConnection
                'Create a new data set
                dsDstData = New DataSet
                'Create a new data set
                dsDstData = New DataSet
                'Set the select statement
                daDataAdapter.SelectCommand = cmdCommand
                'Fill the data adapter with the contents of the query
                daDataAdapter.Fill(dsDstData, "DatabaseData")
                'Set the module level variable for the data table        
                dtDataTable = dsDstData.Tables("DatabaseData")
                'Set the module level variable for the data view
                'dvDataView = New DataView(dsDstData.Tables("DatabaseData"))
                'Clear out the following objects
                daDataAdapter.Dispose()
                daDataAdapter = Nothing
            End With
            If dtDataTable.Rows.Count > 0 Then
                ProgressBar1.Maximum = dtDataTable.Rows.Count
                ProgressBar1.Minimum = 0
                _lngTotalCount = dtDataTable.Rows.Count

            End If
        Catch ex As Exception
        End Try

        


        'For lngLoop As Integer = 0 To arrList.Count - 1

        Dim strLinkInfo As String
        For Each drRow As Data.DataRow In dtDataTable.Rows
            Try

                
                _lngCount += 1

                ProgressBar1.Step = 25
                ProgressBar1.Value = _lngCount
                ProgressBar1.PerformStep()

                strURL = drRow("keyword_url").ToString

                objWebRequest = CType(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest)
                objWebRequest.Method = "GET"
                objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)


                Dim strHeaders As String = objWebResponse.Headers.ToString
                Dim strMailCode As String = String.Empty
                Dim blnMailCode As Boolean = False

                Dim arr As Array = strURL.ToString.Split(CChar("?"))

                If arr.Length > 0 Then
                    Dim arr2 As Array = arr(1).ToString.Split("&")
                    For lngLo As Long = 0 To arr2.Length - 1
                        If arr2(lngLo).ToString.IndexOf("utm_source") > -1 Then
                            Dim arr3 As Array = arr2(lngLo).ToString.Split("=")

                            If arr3(1).ToString.ToLower.IndexOf("email") > -1 Or arr3(1).ToString.ToLower.IndexOf("socialmedia") > -1 Then
                                blnMailCode = True
                            Else
                                strMailCode = arr3(1).ToString.ToLower
                                Exit For
                            End If
                        End If

                        If blnMailCode Then
                            If arr2(lngLo).ToString.IndexOf("mailcode") > -1 Then
                                Dim arr3 As Array = arr2(lngLo).ToString.Split("=")
                                strMailCode =  arr3(1).ToString.ToLower
                                Exit For
                            End If
                        End If
                    Next
                End If
                
                If strHeaders.ToLower.IndexOf(strMailCode) > -1 Then
                    strLinkInfo &= "1" & Chr(9) & strMailCode & Chr(9)
                Else
                    strLinkInfo &= "0" & Chr(9) & "No mailcode present" & Chr(9)
                End If


                strLinkInfo &= strURL & Chr(9)

                Dim strUri As String = objWebResponse.ResponseUri.ToString
                If strUri.ToLower.IndexOf(strURL.ToLower) > -1 Then
                    strLinkInfo &= "1" & Chr(9) & strUri
                Else
                    strLinkInfo &= "0" & Chr(9) & "Incorrect url - " & strUri
                End If

                strLinkInfo &= Chr(10) & Chr(13)

                



            Catch ex As Exception

            Finally
                objWebResponse.Close()
                objWebRequest.Abort()

            End Try

  

        Next
        TextBox1.Text = strLinkInfo

Open in new window

JDEE8297Asked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
Try to add an Application.DoEvents() after the ProgressBar1.PerformStep()
0
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
The same for the label
0
 
JDEE8297Author Commented:
totally forgot about that....:)...I will give it a try tomorrow when I get into work, and see how it goes.
0
 
JDEE8297Author Commented:
thanks, that worked like a charm. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.