简体   繁体   中英

System.Data.OleDb.OleDbException (0x80040E14): Syntax error (missing operator) in query expression 'Email= '12' and Password '12''

it has connected to the database, but when I try to read from the database to validate login, I get this error.

System.Data.OleDb.OleDbException (0x80040E14): Syntax error (missing operator) in query expression 'Email= '12' and Password 'fgrt''.
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
           at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
           at COSSA_E_Voting_System.LoggingIn.guna2Button2_Click(Object sender, EventArgs e) in C:\Users\kusic\Desktop\COSSA E-Voting System\LoggingIn.cs:line 72
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at Guna.UI2.WinForms.Guna2Button.OnClick(EventArgs e)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
        
    

This is the code when the button login is clicked

con.Open();
    OleDbCommand cmd = new OleDbCommand();
    OleDbDataAdapter da = new OleDbDataAdapter();
    // cmd.Connection = con;
    string login = "SELECT * FROM tbl_students WHERE Email= '" + txtEmail.Text + "' and Password '" + txtPassword.Text + "'";
    cmd = new OleDbCommand(login, con);
    
    OleDbDataReader reader;
    reader = cmd.ExecuteReader();
    
    if (reader.Read() == true)
    {
                   
       MessageBox.Show("Email and Password is valid!");
    }

this looks like a bit size error. Try changing (force) your project from ANY cpu to x86, and re-build - see if that works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM