62,046
社区成员
发帖
与我相关
我的任务
分享
protected void but1_Click(object sender, EventArgs e)
{
string UserID;
string UserPwd;
UserID = user_name.Text.Trim();
UserPwd = user_pass.Text.Trim();
string strConnection= "Provider=Microsoft.Jet.OleDb.4.0;Data Source= ";strConnection+=Server.MapPath( "date/admin_info.mdb "); //*就是数据库的名字//嗯~~
OleDbConnection objConnection=new OleDbConnection(strConnection);
objConnection.Open();//打开数据库
OleDbCommand cmd = new OleDbCommand("select count(*) from admin where 用户名=" + UserID + " and 密码= " + UserPwd + "", objConnection);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("http://www.baidu.com");
Response.Write(" <script language='javascript'>alert( '登陆成功! ') </script> ");
objConnection.Close();//要记得关
}
else
{
Response.Redirect("http://www.google.cn");
objConnection.Close();//要记得关
}
}
你肯定是查询条件写错了。你取出dataset看看。看看有没有值。就知道了。