当我运行程序并输入登录详细信息时,按下登录按钮后出现此错误:
"标准表达式中的数据类型不匹配。"在这个表达式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");
}
}
}
}
答案 0 :(得分:1)
密码是保留的字,因此必须加上括号:
string cmdstr = "SELECT [password] FROM admin WHERE ID ='"+textBox1.Text+"'";