Question progress bar control on a big SQL query execution

JSG

New member
Joined
Oct 31, 2022
Messages
1
Programming Experience
Beginner
Hello guys, can you help me to create a progress bar in order to know the status of the sql insert statement?
I've already tried to add a progress bar referring to variables "ì" or "j" in the While statements to execute PerformStep() and invoke Application.DoEvents() for a
Thread.Sleep(40) using the MOD, but whenever I put something after the While instructions, the entire code execution is impacted, taking more than 1 hour to generate the insert?!?!?

my example code:
.
...()

 LstWork = DSO.query("select distinct (workers...


 While LstWork.AtEnd = False

            j = 1
               FuncList = DSO.Query(";with EffectiveYears as (...

               i = 1

                  While ListFunc.NoFim = False
 
                                 field1 = ListFunc.x
                                 field2 = ListFunc.y
                                 field3 = ListFunc.z

                         TSO.ExecuteSQL ( INSERT INTO [dbo].[TBL_Work] ( ColMov1, ColMov2 , ColMov3 ) Values ( " & " Field1 & ", " & " Field2 & "," & " Field3 & ")" )

                   i += 1
                ListFunc.Next()

            End While

              j += 1

    LstWork.Next()

 End While

End Sub
 
A ProgressBar is simply a visual representation of a ratio. You can't visualise a ratio that you can't calculate. How are you going to calculate the progress you want to display?

I would suggest that your best bet would be to just set the Style to Marquee, so the ProgressBar shows that something is happening but not where it is up to. This is how its generally done when you don;t know the end point of a task until you get there.
 
Apart from that, the way you're dealing with that data is horrible. You should be populating a DataTable with all the data first, then saving the lot with a data adapter or possibly even SqlBulkCopy, assuming that this is for SQL Server.
 
Finally, please post your questions in the most appropriate forum, not the first one on the list. This question has nothing at all to do with the VS IDE so it does not belong in a forum for questions on the VS IDE. You're asking a question that is specific to Windows Forms, so the thread belongs in a forum dedicated to that subject. Thread moved.
 
Back
Top