Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to display progress of a running query

Posted on 2004-04-27
4
Medium Priority
?
663 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Integration Management Part 2
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

577 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