2016-03-12 33 views
0
Syntax error (missing operator) in query expression 'Username ='admin' [Password] ='admin' AND AccountType = Admin''. 

暗淡康恩作爲新的OleDbConnection(「提供者= Microsoft.ACE.OLEDB.12.0;數據源= C:\用戶\仁\文件\玉\ VB \ database.accdb「)語法錯誤(缺少運營商)兩個用戶在登錄表單

txtAdmin.Text = "Admin" 

    Dim strsql As New OleDbCommand("select * from Login where Username ='" & txtUsername.Text & "' [Password] ='" & txtPassword.Text & "' AND AccountType = Admin'", conn) 
    Dim uu As New OleDbParameter("UserName", txtUsername.Text) 
    Dim pp As New OleDbParameter("Password", txtPassword.Text) 
    strsql.Connection.Open() 

    Dim reader As OleDbDataReader 
    reader = strsql.ExecuteReader 

    If reader.HasRows Then 
     strsql.Connection.Close() 


     MsgBox(" Successfully Logged in!", vbInformation) 

     frmIndex.Show() 
     desktopFade.Close() 

    ElseIf txtUsername.Text = "" And txtPassword.Text = "" Then 
     MsgBox("Don't leave the fields blank", vbCritical) 
     txtUsername.Focus() 

    Else 

     MsgBox("Your Username or Password is invalid", MsgBoxStyle.Critical) 
     Me.txtUsername.Text = "" 
     Me.txtPassword.Text = "" 
     Me.txtUsername.Focus() 
     strsql.Connection.Close() 


    End If 

我在數據庫中有2個用戶。管理員和用戶。如果用戶名和密碼帳戶類型爲= Admin,則顯示ADMIN帳戶,而如果用戶名和密碼輸入用於用戶,則顯示USER帳戶。在我的代碼上,我試圖首先解決管理,但我需要每個人的幫助。 T.T

回答

0

你會錯過的 「AND」 在這裏:

'" & txtUsername.Text & "' [Password] ='" 

應該

'" & txtUsername.Text & " AND ' [Password] ='" 
+0

吉茲。非常感謝你!我花了2個小時尋找答案。嚴重。謝謝^^ –

+0

@JadeMendoza如果回答問題標記爲答案 –