数据库里有的用户可以判断,没有的在页面上也没有显示,看看我 代码

来源:百度知道 编辑:UC知道 时间:2024/07/02 09:45:52
string str1 = this.Text1.Value.ToString().Trim();
string str2 = this.Password1.Value.ToString().Trim();
string conn = ConfigurationManager.AppSettings["database"];
string sqlcmd = "select * from login where USERNAME='"+str1+"' and PASSWORD = '"+str2+"'";
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand(sqlcmd,con);
SqlDataReader read = cmd.ExecuteReader();
int count = 0;
while (read.Read())
{
count++;
if (count >= 0)
{
Response.Redirect("taxi.aspx");
read.Close();
}
else
{ Response.Write("<script language=javascript>a;ert('登陆失败')</script>"); }
}
con.C

string str1 = this.Text1.Value.ToString().Trim();
string str2 = this.Password1.Value.ToString().Trim();
string conn = ConfigurationManager.AppSettings["database"];
string sqlcmd = "select * from login where USERNAME='"+str1+"' and PASSWORD = '"+str2+"'";
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand(sqlcmd,con);
SqlDataReader read = cmd.ExecuteReader();
int count = 0;
while (read.Read())
{

Response.Redirect("taxi.aspx");
read.Close();
count++;
}
if (count == 0)
this.Label2.Text = "密码错误";
con.Close();

// 这里也可以试试 if (read != null)
while (read.Read())
{
// 执行到这个地方,证明有该用户的数据
// 先