开发者

How make Data Source can read and Connected?

开发者 https://www.devze.com 2023-01-24 13:52 出处:网络
I want to connect data from any folder in my computer.After user clickbrowse button it appear any location for access database folder.After that user click connect button and but i have facing connect

I want to connect data from any folder in my computer.After user click browse button it appear any location for access database folder.After that user click connect button and but i have facing connection problem.

Under Browser Button

  Using ofd As New OpenFileDialog
        ofd.Filter = "mdb files |*.mdb"
        开发者_如何学运维ofd.Title = "Select File"
        ofd.ShowDialog()

        TextBox1.Text = ofd.FileName

        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            MessageBox.Show("Hang amik " & TextBox1.Text)
        End If
    End Using

Under connect button

 Dim connetionString As String
    Dim cnn As OleDbConnection

    connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & TextBox1.Text  "
    cnn = New OleDbConnection(connetionString)


    Try
        cnn.Open()
        MsgBox("Connection Open ! ")
        cnn.Close()
    Catch ex As Exception
        MsgBox("Can not open connection ! ")
    End Try

My main problem what code must inserted for connecting to database?

Data Source= & TextBox1.Text

My code not work.

Using Visual Studio 2010.vb.net.Thank You Very Much.


Fix:

connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & TextBox1.Text 

Use String.Format to best improve usability in build string with variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消