在c#中怎样实现SQL数据库的查找并与之匹配功能???
最近做一个登录系统的的取回密码的页面,灾在取回过程中需要遍历数据库的用户名和密码,当填写完用户名后,要求实现查找数据库是否存在用户,若存在将数据库中注册问题提取出来,请求回答,回答正确取回密码成功。问题出现在系统找不到已经存在的用户名的问题,故无法提取出来,请大家帮忙指点,问题是不是出现在数据库查询语句上,我的查询语为:
string str = "select*from pwd where id=1";
string sd = "server=localhost;database=tongxun;user=yijia;password=111";
SqlConnection cn = new SqlConnection(sd);
SqlCommand cmd = new SqlCommand(str,cn);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (this.TextBox1.Text.Trim() == (string)dr["user"])
{
this.Label5.Text = (string)dr["wenti"];
}
else
{
this.Label5.Text= "用户名不存在";
}
if (this.TextBox2.Text == (string)dr["daan"])
{
this.Label5.Text = "您的密码已发送至"+(string)dr["Email"];
this.TextBox2.Enabled = false;
}
this.TextBox1.Enabled = false;
}
此代码可以实现取回密码功能,但是有局限性,因为取回的密码的用户id是1,不适用于其他用户。