如何连接ACCESS数据库验证登录?
试了以下代码,提示 OleDbDataReader reader = cmd.ExecuteReader();这一句错误:
“标准表达式中数据类型不匹配。 ”
请大侠帮忙!!!
string strPath = Application.StartupPath + "\\gk.mdb";
string strconn = "provider=microsoft.jet.oledb.4.0;data source='" + strPath + "'";
OleDbConnection oleconn = new OleDbConnection(strconn);
string strcmd = "select * from tb_user where username='" + txtuser.Text.Trim() + "'and userpwd='" + txtpwd.Text.Trim() + "' ";
OleDbCommand cmd = new OleDbCommand(strcmd, oleconn);
oleconn.Open();
OleDbDataReader reader =cmd.ExecuteReader();
try
{
reader.Read();
if (reader.HasRows)
{
string pp = txtuser.Text;
// Frm_Main newfrm = new Frm_Main(pp);
frm_main main = new frm_main();
main.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtuser.Text = "";
txtpwd.Text = "";
txtuser.Focus();
}
}
finally
{
if (reader != null)
oleconn.Close();
}
[ 本帖最后由 zjdjh 于 2012-3-12 21:46 编辑 ]