?
Solved

How to display progress of a running query

Posted on 2004-04-27
4
Medium Priority
?
660 Views
Last Modified: 2008-02-01
hi,

I am running a query in access database. The query takes about 1 minute to execute. during this time I want to show the user the progress of the query in a progress bar, otherwise the user thinks as the application stopped responding.

Is there any way to do this? please help. I am very new to .NET


the code I am using is

        Dim qstr, strWhere, buildings As String
        Dim reportDS As New DataTable
        Dim dbconnection As New OleDbConnection(connectionString)
        Dim Adapter As New OleDbDataAdapter

        buildings = GetBuildingSelection()
        strWhere = " WHERE (((ACCOUNT) = " + Str(account_no) + ") AND ((BUILDINGNUM) In (" + buildings + ")))"

        qstr = "SELECT * FROM qryDisposalCost" + strWhere

        Adapter.SelectCommand = New OleDbCommand(qstr, dbconnection)
        Adapter.SelectCommand.Connection.Open()
        Adapter.Fill(reportDS)   'This line takes about 1 minute to finish


0
Comment
Question by:bansidhar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 900 total points
ID: 10927087
I don't think you can do this during a Fill, why don't you just show a small splash screen before the fill and close it after the fill.
0
 
LVL 11

Author Comment

by:bansidhar
ID: 10927528
that i am doing.
But because the query takes about a minute or more, and it uses hevy resources the user thinks it as a system hang and often reboots the machine.

and he is not allowing me to optimize the database and querries.

bansidhar
0
 
LVL 27

Expert Comment

by:planocz
ID: 10927786
Hi bansidhar,

Here is some code that I use for a splash screen with a timer. You can adjust the timer to  that one minute that you need.

Public Class frmSplash
    Inherits System.Windows.Forms.Form
    Public Shared frmMain As New frmMain
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents StartTimer As System.Windows.Forms.Timer
    Friend WithEvents LinkLabel As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmSplash))
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.StartTimer = New System.Windows.Forms.Timer(Me.components)
        Me.LinkLabel = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'ProgressBar1
        '
        Me.ProgressBar1.Location = New System.Drawing.Point(8, 280)
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(144, 16)
        Me.ProgressBar1.TabIndex = 0
        '
        'Timer1
        '
        Me.Timer1.Interval = 300
        '
        'StartTimer
        '
        '
        'LinkLabel
        '
        Me.LinkLabel.BackColor = System.Drawing.Color.Transparent
        Me.LinkLabel.ForeColor = System.Drawing.Color.White
        Me.LinkLabel.Location = New System.Drawing.Point(372, 280)
        Me.LinkLabel.Name = "LinkLabel"
        Me.LinkLabel.Size = New System.Drawing.Size(156, 16)
        Me.LinkLabel.TabIndex = 1
        Me.LinkLabel.Text = "Please Wait..... Form Loading"
        '
        'frmSplash
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(528, 298)
        Me.ControlBox = False
        Me.Controls.Add(Me.LinkLabel)
        Me.Controls.Add(Me.ProgressBar1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmSplash"
        Me.Opacity = 0
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.TopMost = True
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub beginLoadingComponents()
        Me.LinkLabel.Text = "Loading Main Form"
        Me.Timer1.Enabled = True
        Me.ProgressBar1.Visible = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.ProgressBar1.Value += Me.ProgressBar1.Maximum / 10
        If Me.ProgressBar1.Value >= 90 Then
            Me.LinkLabel.Text = "Main Form loaded"
        End If
        If Me.ProgressBar1.Value >= Me.ProgressBar1.Maximum Then
            Timer1.Enabled = False
            Me.Visible = False
            frmMain.ShowDialog()    '<--- show your main form
            Application.Exit()      '<--- exit
        End If
    End Sub

    Dim elapsed As Short = 0
    Private Sub StartTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartTimer.Tick
        elapsed += 1
        Me.Opacity = elapsed * 0.1
        If elapsed >= 10 Then
            Me.LinkLabel.Visible = True
            Me.StartTimer.Enabled = False
            Me.beginLoadingComponents()
        End If
    End Sub

    Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartTimer.Enabled = True
    End Sub
End Class
0
 
LVL 11

Author Comment

by:bansidhar
ID: 10935352
I think I have to run the query and the progress bar in different threads, because during the query running no other events are handled by the application.

 I may also have to calculate the query speed (network connectivity speed) of the target machine to calculate the increments and max value of the progress bar.


bansidhar
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question