0

请帮帮我,我得到 ---MessageBox.Show("登录不成功,再试一次!"); ----每次我输入正确的用户名并通过。可能是什么问题?谢谢

我似乎不想验证..

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!");
                }
            }
        }
    }
4

1 回答 1

0

来自MSDN

当 CommandType 设置为 Text 时,OLE DB .NET 提供程序不支持将参数传递给 SQL 语句或由 OleDbCommand 调用的存储过程的命名参数。在这种情况下,必须使用问号 (?) 占位符。

尝试像这样更改您的查询:

OleDbCommand cmd = new OleDbCommand("Select * From userAndPass Where ID = ? AND pass = ?", conn);
于 2013-10-30T05:12:24.290 回答