Click here to Skip to main content
15,668,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi! everyone,I am just a newbie in Visual Basic.Net and Oracle stored procedure.

**Here's my code in calling the rows in the database**

Public Function RESA_Checker(ByVal stores As String, ByVal bus_date As String, ByVal warehouse As String)
        dt = New DataTable
        bg.GetProcDataTable(connStr, "SALES_CHECKER.procedure_checker")
        cmd.Parameters.Add(New OracleParameter("stores", OracleDbType.Varchar2)).Value = stores
        cmd.Parameters.Add(New OracleParameter("bus_date", OracleDbType.Varchar2)).Value = bus_date
        cmd.Parameters.Add(New OracleParameter("warehouse", OracleDbType.Varchar2)).Value = warehouse
        cmd.Parameters.Add(New OracleParameter("O_OUTPUT", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
        adap_or.SelectCommand = cmd

        Return dt
    End Function

My purpose is that the user will be informed through a dialog box with progress bar or animated gif, that the form is loading and still fetching records from the database says "Please wait"/"Searching", and prevent confusion to the user, of having thought that the form is crashed.

P.s. It would be helpful if give the links of the video tutorials.
I do hope you could help me , Thanks.

What I have tried:

I have this set of codes where I found on the internet. It works but, how can I convert this importing CSV file from fetching rows from the database using Oracle stored procedure.

Dim strRow As String()              'String array to read all fields in a row
    Dim dblAmount As Double             'Variable for total amount 
    Dim blnReported As Boolean = True   'Flag to check progress report completed or not

    'Create TextFieldParser class to parse the stock.csv file in the current location
    Dim txtFile As FileIO.TextFieldParser

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Allow background operation to be cancelled
        bgWorker.WorkerSupportsCancellation = True

        'Allow background operation to report progress
        bgWorker.WorkerReportsProgress = True

        'Disable Stop Button. It is enabled only after start
        'button is pressed
        btnStop.Enabled = False

        'set status message
        lblStatus.Text = "Press Start to import data from csv."

        'Add columns to the grid
        dgvCSVData.Columns.Add("colNo", "No")
        dgvCSVData.Columns("colNo").Width = 30
        dgvCSVData.Columns.Add("colDate", "Date")
        dgvCSVData.Columns("colDate").Width = 60
        dgvCSVData.Columns.Add("colItem", "Item")
        dgvCSVData.Columns("colItem").Width = 120
        dgvCSVData.Columns.Add("colQty", "Quantity")
        dgvCSVData.Columns("colQty").Width = 50
        dgvCSVData.Columns.Add("colUnit", "Unit")
        dgvCSVData.Columns("colUnit").Width = 30
        dgvCSVData.Columns.Add("colAmt", "Amt")
        dgvCSVData.Columns("colAmt").Width = 60
    End Sub

    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        'Disable Start button and Enable Stop
        btnStart.Enabled = False
        btnStop.Enabled = True

        'set status message
        lblStatus.Text = "Importing data from CSV file."

        'Start time-consuming operation in background
        Call bgWorker.RunWorkerAsync()
    End Sub

    Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
        'Enable Start button and disable Stop
        btnStart.Enabled = True
        btnStop.Enabled = False

        'Stop background operation

        'set status message
        lblStatus.Text = "Import cancelled. Press Start again."
    End Sub

    Private Sub bgWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgWorker.DoWork
        Dim intCount As Int16 = 0
        txtFile = New FileIO.TextFieldParser("stock.csv")
        'Specify structure of the file
        txtFile.TextFieldType = FileIO.FieldType.Delimited

        'Skip header row

        'Start reading data from file
        While Not txtFile.EndOfData

            If bgWorker.CancellationPending Then
                e.Cancel = True
                Exit Sub


                'Wait for Progress Report to finish
                While Not blnReported
                End While

                'Read all field in a row into a string array
                strRow = txtFile.ReadFields()

                'Do some calculations and assign value to data grid
                dblAmount = CDbl(strRow(3)) * CDbl(strRow(4))

                'Add some sleep to simulate a long running operation

                'Progress report pending
                blnReported = False

                'increment counter
                intCount += 1

                'Report the progress
                bgWorker.ReportProgress(10, intCount)

            End If

        End While
    End Sub

    Private Sub bgWorker_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bgWorker.ProgressChanged
        'Copy values to data grid
        dgvCSVData.Rows(dgvCSVData.CurrentRow.Index - 1).Cells("colAmt").Value = dblAmount

        pgbCopyProgress.Value = e.UserState
        'Progress report finished
        blnReported = True
    End Sub

    Private Sub bgWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
        If e.Cancelled Or Not IsNothing(e.Error) Then
            'Clear the data grid
            'Progress completed
            pgbCopyProgress.Value = 100

            'Release txtfile
            btnStop.Enabled = False
            btnStart.Enabled = True

        End If
    End Sub
Updated 29-May-18 20:45pm

1 solution

You can use progress bar control over form to show the status progress over the screen
like 10%, 40% and 100%.

We have progress bar control over, drag and drop that control over the screen.

ProgressBar1.Value = 10
--- Perform some task.

ProgressBar1.Value = 40
--- Perform some task.

ProgressBar1.Value = ProgressBar1.Maximum; // means task completed

ProgressBar1.Value = 0

Now if you are calling some functions so you can pass the reference of this Progressbar
control over functions and manage the status of progress bar from functions also.

Public  Function SyncToOracle(ByRef p_objProgressBar As ProgressBar)

p_objProgressBar.Value = 10

ProgressBar1.Value = 40
--- Perform some task.

ProgressBar1.Value = ProgressBar1.Maximum // means task completed

ProgressBar1.Value = 0

End Function

--You call the function and pass the object of progress bar control over the function
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900