I am using Visual Basic Express 2010. Form 3 has code to import a csv file into a DataGridView while creating a DataSet. This event happens when I open Form 3. The path to the file is in the code. I would like to have a button on Form 1 that opens an OpenFileDialog so the user can browse for the csv file. Once the user selects the file, the DataGridView and DataSet on Form 3 initiate. The code I am currently using is below. Is there a way to edit the code to have an open file dialog from a button on Form 1 and not auto load through a pathway? Any assistance would be appreciated.
Public Class Form3
Private Sub Form3_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim file As String = "test.csv"
Dim path As String = "C:\Users\laptop\Desktop\"
Dim ds As New DataSet
End If
Try
If IO.File.Exists(IO.Path.Combine(path, file)) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=Yes;IMEX=1;FMT=CSVDelimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGridView1.DataSource = ds.Tables(0)
End Sub