这是我的代码:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _byval As System.EventArgs) Handles Button1.Click
Dim dbProvider As String
Dim dbSource As String
Dim con As New OleDb.OleDbConnection
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
[b]dbSource = "Data Source = \AddressBook1" & My.Application.Info.DirectoryPath[/b]
con.ConnectionString = dbProvider & dbSource
con.Open()
MsgBox("Database is now open")
con.Close()
MsgBox("Database is now Closed")
End Sub
End Class
在第8行,我指定了我为源设置的数据源:dbSource =“Data Source = \ AddressBook1”& My.Application.Info.Directory路径,因为当我每次复制文件夹并将其安装在另一台计算机上时,我使用它与之前的xml数据库一起工作..所以我现在用我的访问数据库对其进行了调整,但遗憾的是我收到错误时在con.open“NOT A VALID FILE NAME”..名称正确,我还检查了拼写和应用程序bin文件夹中的文件夹。
my.application.info.directory的任何想法或类似命令,以便我在另一台计算机上安装它时不会遇到任何问题?
提前谢谢
答案 0 :(得分:0)
你应该转义字符串 - 空格可能会导致问题:
dbSource = "Data Source = ""\AddressBook1" & My.Application.Info.DirectoryPath & """"