简体   繁体   中英

C# database Access not validating

Please help me, Im getting ---MessageBox.Show("Login NOT Successfull, Try again!"); ----everytime I put the right username and pass. What can be the problem? Thanks

I seems it dosent want to validate..

using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Data.OleDb;

    namespace posSystem
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void btnLogin_Click(object sender, EventArgs e)
            {



                OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=userName.accdb");

                OleDbCommand cmd = new OleDbCommand("Select * From userAndPass Where ID = @id AND pass = @password", conn);
                cmd.Parameters.AddWithValue("@id", txtBoxUserName.Text);
                cmd.Parameters.AddWithValue("@password", txtBoxPassword.Text);
                conn.Open();

                OleDbDataReader re = cmd.ExecuteReader();

                if(re.Read())
                {

                    MessageBox.Show("Login Successfull"); 



                }
                else{
                MessageBox.Show("Login NOT Successfull, Try again!");
                }
            }
        }
    }

From MSDN :

The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used.

Try to change your query like this:

OleDbCommand cmd = new OleDbCommand("Select * From userAndPass Where ID = ? AND pass = ?", conn);

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