Q:

OleDb set Data Source to load file window

Private Sub Button_Import_Click(sender As Object, e As EventArgs) Handles Button_Import.Click
    Try
        Dim MyConnection As OleDb.OleDbConnection
        Dim Ds As System.Data.DataSet
        Dim MyAdapter As System.Data.OleDb.OleDbDataAdapter

        MyConnection = New System.Data.OleDb.OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\matil\Desktop\KontaktDaten.xlsx';Extended Properties=Excel 8.0"))
        MyAdapter = New System.Data.OleDb.OleDbDataAdapter("Select * from [KontaktDaten$]", MyConnection)
        Ds = New System.Data.DataSet
        MyAdapter.Fill(Ds)
        Me.DataGridView_Kontakte.DataSource = Ds.Tables(0)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

In the above code, I’m importing an Excel data file to a datagridview, but I want to make it possible for the user to choose his own data source in a load file window. How can I achieve that?, I already tryed modifying my code like this, but I always get the error "The Microsoft Acces database cannot open or write to the file".
Dim Path As New OpenFileDialog()
MyConnection = New System.Data.OleDb.OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", Path))

A:

To answer your comment, your problem is likely easy to handle. I use this code to get a filename:
    Dim indlg As New OpenFileDialog
    indlg.DefaultExt = "csv"
    indlg.Filter = "Texte|*.txt|CSV-Files|*.csv|Alle Files|*.*"
    indlg.Title = "Textdatei"
    indlg.Multiselect = False
    If indlg.ShowDialog <> DialogResult.OK Then
        MessageBox.Show("Funktionsabbruch.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Exit Sub
    End If

In your case, there is just a line missing:
MyConnection = New System.Data.OleDb.OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & indlg.FileName & ";Extended Properties=Excel 8.0"))

