簡體   English   中英

'System.Data.OleDb.OleDbException:條件表達式中的數據類型不匹配。' 錯誤

[英]'System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.' error

當我運行程序並輸入登錄詳細信息時,按下登錄按鈕后出現此錯誤:

“條件表達式中的數據類型不匹配。” 在這個表達式中 dr = cmd.ExecuteReader();

我是新手。 該怎么辦?

namespace Inventory_System
{
    public partial class MainForm : Form
    {
      private OleDbConnection mycon;
      private OleDbDataReader dr=null;
      private OleDbCommand cmd=null;
      public MainForm()
      {
        mycon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\User\Documents\SharpDevelop Projects\Inventory System\inventory.mdb;Persist Security Info=False");
        InitializeComponent();  
      }
      void Button2Click(object sender, EventArgs e)
      {
        this.Close();
      }
      void Button1Click(object sender, EventArgs e)
      {
        mycon.Open();
        string cmdstr = "SELECT password FROM admin WHERE ID ='"+textBox1.Text+"' ";
        cmd = new OleDbCommand(cmdstr, mycon);
        dr = cmd.ExecuteReader();
        string[] login = new string[3];

        while (dr.Read())
        {
            login[3] = (dr["password"].ToString());
        }

        dr.Close();
        mycon.Close();

         if (maskedTextBox1.Text == login[3])
        {
           MessageBox.Show("LOG-IN SUCCESFUL!", "Confirmation Message");
           Form control = new MainForm();
           control.Show();
           this.Hide();
        }
        else
        {
            MessageBox.Show("LOG-IN FAILED!", "Confirmation Message");
        }
    }
}
}

密碼是保留字,因此必須用括號括起來:

string cmdstr = "SELECT [password] FROM admin WHERE ID ='"+textBox1.Text+"'";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM