Well, i really got stuck into this problem.

In my project i wish the user to be able to select a database
using an open file dialog box.
I am unable to connect with this database.

i used the code..

createConnection.ConnectionString = _
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Tostring(ofdselectdatabase.FileName)"

and

createConnection.ConnectionString = _
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ofdselectdatabase.FileName"

The exception raised was that the compiler understood the two lines:

Tostring(ofdselectdatabase.FileName)
and
ofdselectdatabase.FileName

as the path itself rather than a container referencing the path.

I am really stuck here an need to complete this project within the week.plz Help. Urgent

Imports Microsoft.Win32

Public Class FormHeader

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim ofd As OpenFileDialog = New OpenFileDialog()
		ofd.InitialDirectory = "C:\data"
		ofd.Multiselect = False
		If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then
			Dim connStr As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", ofd.FileName)
			Console.WriteLine(connStr)
		End If
	End Sub
End Class
Imports Microsoft.Win32

Public Class FormHeader

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim ofd As OpenFileDialog = New OpenFileDialog()
		ofd.InitialDirectory = "C:\data"
		ofd.Multiselect = False
		If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then
			Dim connStr As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", ofd.FileName)
			Console.WriteLine(connStr)
		End If
	End Sub
End Class

Thanks for the bit.
i used the code in this way:

Dim DatabasePath As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", ofdselectdatabase.FileName)

which gave me the connection string.

which i used in this code ::

Private createConnection As New OleDb.OleDbConnection()
Public Sub createconn()
        Dim newConnection As New OleDb.OleDbConnection()
        createConnection.ConnectionString = "DatabasePath"
        createConnection.Open()
    End Sub

which i know now is wrong as i received an exception :::

Format of the initialization string does not conform to specification starting at index 0.

what do i do now..:"""????

hi...

used

newConnection.ConnectionString() = DatabasePath

which works...

I'm glad you found a solution to your problem.

Please mark this thread as solved if your question has been answered and good luck!

This question has already been answered. Start a new discussion instead.