if (Page.IsValid) {
if (this.username.Text != "")//判断用户名是否未空 { if (this.password.Text != "")//判断密码是否未空 {
string sql; sql = "select count(*) from userinfo where username='" + this.username.Text + "' and pwd='" + this.password.Text + "'";//建立sql查询语句 try { OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("./App_Data/db1.mdb"));//建立数据库连接 conn.Open(); OleDbCommand cmd = new OleDbCommand(sql, conn); int state =Convert.ToInt32( cmd.ExecuteScalar());//执行sql语句,并返回获得值 if (state == 0 || state > 1)//如果数据中没有记录或有多条记录则抱错 { this.Label2.Text = "用户不存在,请检测用户名和密码是否正确!"; } else { this.Label2.Text = "登入成功!" ;
} conn.Close();
} catch (Exception a) { Response.Redirect("Detail.aspx"); } } else { this.Label2.Text = "验证码不正确,请重新输入!"; } } else { this.Label2.Text = "验证码没有填写!";
} } else { this.Label2.Text = "密码没有填写!";
} }
我可以运行(但是没有判断用户名跟密码是否正确,请高手帮我修改下,只要能实现验证即可,感谢,比较急 }
if (state == 0 || state > 1)//如果数据中没有记录或有多条记录则抱错 { this.Label2.Text = "用户不存在,请检测用户名和密码是否正确!"; } 这个要来干嘛?
if (this.username.Text != "")//判断用户名是否未空 { if (this.password.Text != "")//判断密码是否未空 { string sql; sql = "select count(*) from userinfo where username='" + this.username.Text + "' and pwd='" + this.password.Text + "'";//建立sql查询语句 try { OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("./App_Data/db1.mdb"));//建立数据库连接 conn.Open(); OleDbCommand cmd = new OleDbCommand(sql, conn); int state =Convert.ToInt32(cmd.ExecuteScalar());//执行sql语句,并返回获得值 if (state > 0) { this.Label2.Text = "登入成功!" ; } else//如果数据中没有记录或有多条记录则抱错 { this.Label2.Text = "用户不存在,请检测用户名和密码是否正确!"; } conn.Close(); } catch (Exception a) { Response.Redirect("Detail.aspx"); } } else{ this.Label2.Text = "验证码不正确,请重新输入!"; } } else{ this.Label2.Text = "验证码没有填写!"; } } else{ this.Label2.Text = "密码没有填写!"; }
|