Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim dA As OleDb.OleDbDataAdapter
Dim dS As New DataSet
Dim SQL As String
Private Sub AbrirToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AbrirToolStripMenuItem.Click
Dim strFileName As String
Dim ClikedOk As Integer
OpenFD.InitialDirectory = "C:\"
OpenFD.Title = "Ubica la base de datos"
OpenFD.Filter = "Agenda|Agenda.mdb"
OpenFD.ShowDialog()
If ClikedOk = DialogResult.OK Then
strFileName = OpenFD.FileName
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = Agenda.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
SQL = "SELECT * FROM Contactos"
dA = New OleDb.OleDbDataAdapter(SQL, con)
dA.Fill(dS, "Agenda")
con.Close()
MaxRows = dS.Tables("Agenda").Rows.Count
inc = -1
End If
End Sub
我想要做的是:
用户应该按菜单项并选择数据库文件,然后数据源将被定向到用户指向数据库文件的位置。我应该在“dbSource = Data Source = ...”行中输入什么?访问数据库是 .mdb,因为我在使用 .accdb 时遇到了麻烦