我想检查 CNIC 是否没有。已输入的 tat 用户在我的表中不存在,那么我不希望他继续进行注册过程...
这是代码,其中一部分 不起作用..我哪里错了?
con.Open();
string cmdStr = "Select count(*) from Registration where UserName='" + TextBoxUN.Text + "'";
string cmdCnic = "Select count(*) from List_CNIC where CNIC='" + TextBoxCNIC.Text + "'";
SqlCommand userExist=new SqlCommand(cmdStr, con);
SqlCommand cnicExist=new SqlCommand(cmdCnic,con);
int temp=Convert.ToInt32(userExist.ExecuteScalar().ToString());
int tempCnic = Convert.ToInt32(cnicExist.ExecuteScalar().ToString());
con.Close();
if (temp==1)
{
Session["name1"] = TextBoxFN.Text;
Session["UserName"] = TextBoxUN.Text;
Response.Redirect("Error.aspx");
}
if (!(tempCnic==1))
{
Session["nameFull"] = TextBoxFN.Text;
Session["CNIC"] = TextBoxCNIC.Text;
Response.Redirect("Error_InvalidCNIC.aspx");
}
我正在检查用户名是否存在的代码部分工作正常,但检查tempCnic。即使用户没有输入任何内容 ,它也会自动重定向到页面Error_InvalidCNIC.aspx 。
代码有什么问题???