菜鸟数据库连接求助
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=C:\\ljdata.mdb";
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
OleDbCommand cmd = new OleDbCommand("select * from [user] where [user]='" + userid.Text + "' and [psd]='" + psd.Text + "'",objConnection);
OleDbDataReader daRead = cmd.ExecuteReader();
if (daRead.RecordsAffected!=0) // 用户名存在
{
main lvFrm = new main();
this.Hide();
lvFrm.Show();
}
else // 用户名 不存在
{
MessageBox("用户名或密码错误!!");
}
想做一个登陆界面,但是不用用户名和密码也能登陆,根本没有跟数据库数据进行比较。刚学习编程,非常菜鸟,希望高手指点一二,万分感谢
------解决方案--------------------
OleDbCommand cmd = new OleDbCommand("select count(*) from [user] where [user]='" + userid.Text + "' and [psd]='" + psd.Text + "'",objConnection);
int count=(int)cmd.ExecuteScalar();
if(count>0)
//验证通过;
else
//验证不通过。