无法使用VB.net连接到Access

无法使用VB.net连接到Access,vb.net,Vb.net,我想为我的应用程序创建一个登录页面。当一切都完成了,我想登录,它总是显示 错误: Microsoft Jet数据库引擎无法打开文件“C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug”。它已被其他用户以独占方式打开,或者您需要查看其数据的权限 代码: Imports System.Data.OleDb Public Class Login Dim path = System.Windows.Forms

我想为我的应用程序创建一个登录页面。当一切都完成了,我想登录,它总是显示

错误:

Microsoft Jet数据库引擎无法打开文件“C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug”。它已被其他用户以独占方式打开,或者您需要查看其数据的权限

代码:

Imports System.Data.OleDb

Public Class Login
    Dim path = System.Windows.Forms.Application.StartupPath
    Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub

Private Sub loginbtn_Click(sender As Object, e As EventArgs) Handles loginbtn.Click
    Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug;")
    Dim command As New OleDbCommand("SELECT [ID] FROM [User] WHERE [usernameField] = Username AND [passwordField] = Password", connection)

    Dim usernameparam As New OleDbParameter("Username", Me.usernamebox.Text)
    Dim passwordparam As New OleDbParameter("Password", Me.passwordbox.Text)

    command.Parameters.Add(usernameparam)
    command.Parameters.Add(passwordparam)
    command.Connection.Open()
    Dim reader As OleDbDataReader = command.ExecuteReader()
    If reader.HasRows Then
        MessageBox.Show("Login Succesful!")
        passwordbox.Text = ""
        Me.Hide()
        Main.Show()

    Else
        MessageBox.Show("Username and Password are incorrect!")
        passwordbox.Text = ""
    End If

    command.Connection.Close()
End Sub


Private Sub exitbtn_Click(sender As Object, e As EventArgs) Handles exitbtn.Click
    Me.Close()
    End Sub
End Class
换行

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug;")

或者在输出目录中加载数据库

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\YourMSAccessDB.mdb;")
'".\" is equivalent to your output directory or where your application (exe file) is located.

您是否专门使用ms access打开access数据库?如何检查我是否已打开@杰:谢谢你的编辑。此站点仍然是新的:)哦,对不起,您没有在连接字符串中指定ms access文件名。啊,是的,您是对的。但是在我指定它之后,错误就改变了。找不到文件“C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug\CSS.mdb”。请使用windows资源管理器浏览此“C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug”,查看CSS.mdb文件是否存在,或者需要将该文件复制到其中。
Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\YourMSAccessDB.mdb;")
'".\" is equivalent to your output directory or where your application (exe file) is located.