0
我想爲我的應用程序創建一個登錄頁面。當一切都已經完成了,我想登錄它總是顯示無法連接到訪問使用VB.net
錯誤:
Microsoft Jet數據庫引擎無法打開文件「C:\用戶\吉奧\文檔\的Visual Studio 2012 \項目\ CSS \ CSS \ BIN \調試」。它已經由另一個用戶專門打開,或者您需要查看其數據的權限。
代碼:
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
您是否使用ms訪問權限專門打開了訪問數據庫? – Jade
如何檢查我是否有這樣做或不是玉? @jay感謝您的編輯。這個網站還是新的:) – Bento
哦,對不起,你沒有在連接字符串中指定ms訪問文件名。 – Jade