Save file Dialog and Progress Bar

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi everyone,


How can i incorporate Save File Dialog with Progress Bar.
I have create a Save File Dialog for my file upload.
I'm asking for advice on how i can achieve this goal.

Thanks in advance.

Here is may code for Save File Dialog
VB.NET:
Dim odlg As New Windows.Forms.OpenFileDialog()
        odlg.Multiselect = True
        odlg.Title = "Select DBF File"
        odlg.InitialDirectory = "C:\"


        odlg.Filter = "DBF Files(*.dbf)|*.dbf|All Files(*.*)|*.*"
        odlg.FilterIndex = 1
        odlg.RestoreDirectory = True
        If odlg.ShowDialog() = DialogResult.OK Then
                    GetDBFDatatoGridView(odlg.FileName)
                    Dim w As String = System.IO.Path.GetFileNameWithoutExtension(odlg.FileName)
                    Dim x As Integer = DataGridView.Columns.Count
                    DataGridView.DataSource = Nothing
                    DataGridView.Refresh()
                    PopulateDataGridView(w(w.Length - 1))
             
            End If
       
            FileNameToMove = odlg.SafeFileName
                'Application.DoEvents()
        End If

Populating my Datagrid.
VB.NET:
Public Sub GetDBFDatatoGridView(ByVal strFileName As String)
        Dim DBFcon As OdbcConnection
        Dim DBFconnectionString As String


        DBFconnectionString = "Driver={Microsoft dBASE Driver (*.dbf)};" + "Driverid=277;" + "Dbq=" + System.IO.Path.GetFullPath(strFileName).Replace(System.IO.Path.GetFileName(strFileName), "")
        DBFcon = New OdbcConnection(DBFconnectionString)
        Dim strDBFQuery As String = "Select * from [" + System.IO.Path.GetFileName(strFileName) + "]"
        Try
            DBFcon.Open()
            Dim DBFcmd = DBFcon.CreateCommand
            DBFcmd.CommandText = strDBFQuery
            DBFcmd.CommandType = CommandType.Text
            Dim dr As OdbcDataReader = DBFcmd.ExecuteReader
            Dim dt As New DataTable
            dt.Load(dr)
            DataGridView.DataSource = dt
            ClearDT = dt
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            If DBFcon IsNot Nothing Then
                DBFcon.Close()
                DBFcon.Dispose()
            End If
        End Try
    End Sub

Saving Data from Datagridview
VB.NET:
 Dim con As New SqlConnection(SQLConn)


                con.Open()
                           Try


                    For i As Integer = 0 To Me.DataGridView.Rows.Count - 1
                        Dim cmd As SqlCommand = con.CreateCommand


                        cmd.CommandText = "usp_InsertOneOpus"
                        cmd.Parameters.AddWithValue("@a", DataGridView.Rows(i).Cells(0).Value)
                        cmd.Parameters.AddWithValue("@b", DataGridView.Rows(i).Cells(1).Value)
                        cmd.Parameters.AddWithValue("@c", DataGridView.Rows(i).Cells(2).Value)
                        cmd.Parameters.AddWithValue("@d", DataGridView.Rows(i).Cells(3).Value)
                        cmd.Parameters.AddWithValue("@e", DataGridView.Rows(i).Cells(4).Value)
                        cmd.Parameters.AddWithValue("@f", DataGridView.Rows(i).Cells(5).Value)
                        cmd.CommandType = CommandType.StoredProcedure
                        cmd.ExecuteNonQuery()
                    Next
   


                Catch ex As Exception
     
                Finally
                    If con IsNot Nothing Then
                        con.Close()
                        con.Dispose()
                    End If
                End Try
 
First of all, you keep saying "Save File Dialog". I see an OpenFileDialog but I don't see a SaveFileDialog anywhere. That's kinda fundamental to the whole problem so you should start by providing a FULL and CLEAR explanation of the problem, minus stuff like that that doesn't actually make sense.

Regardless, there is no integration between a SaveFileDialog and a ProgressBar. You can use them both in the same app but there is no integration. A SaveFileDialog exists to allow the user to select where to save a file. That's it, that's all. It has nothing to do with actually saving the file. A ProgressBar is simply a visual representation of a fraction. It has nothing to do with saving any files either.

What is it that you really want to know? Is it how to display the progress of a save operation? Is it how to display the saving of the contents of your DataGridView to your database? That has nothing to do with files, let alone a SaveFileDialog.

If you want to display a progress to the user then you have to be able to measure that progress. What can you measure in your app that you would want to display to the user to indicate a progress?
 
Hi jmcilhinney's,Thanks for that clarification.Yes, i want the user to see the progress indicating when uploading the data.I have been focusing on the Save File Dialog instead of the data.Thanks again jmcilhinney's.
 

Latest posts

Back
Top