Solved

How to display progress of a running query

Posted on 2004-04-27
4
650 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
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 300 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now