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
Populating my Datagrid.
Saving Data from Datagridview
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