这里是C#代码在检索密码代码总是返回重试,而不是恢复密码
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=Mrunal;Initial Catalog=JobPortalDB;Integrated Security=True");
conn.Open();
string s1 = "select password from Registration where SecurityQues='" + seqQue.SelectedItem.Text + "' and SecurityAns='" + TextBox2.Text + "' and emailId='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(s1, conn);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
Label2.Text = dr[0].ToString();
else
Label2.Text = "try again";
}
码不显示错误,但它无法正常工作。
如果有人得到更正,请帮忙吗?
在此先感谢
你调试代码,并检查您的变量?什么是_不完全工作?什么是你的专栏类型?您的查询是否返回SSMS中的任何数据?您应该始终使用参数化查询。这种字符串级联对于SQL注入攻击是开放的。并使用using语句来处理你的sql连接和命令。 – 2015-02-10 09:56:53
在db中执行相同的查询并检查它是否真的存在? – 2015-02-10 09:57:39
得到了上述错误。实际上它在secQue字段中存储零,同时从下拉列表中进行选择。感谢导航。但我仍然没有得到,为什么dropdownlist存储零,而不是选择的价值形式dropdownlist – 2015-02-10 10:08:29