用户登录为什么验证不了呢?
代码如下: (为什么用户名和密码都正确它还是进不了"if (temp=="yes")"语句呢?一直跑到"else"语句,不知道哪里出错,请教高手们.)
string userName = userTb.Text;
string password = pwdTb.Text;
string connstr ="Data Source=localhost;Initial Catalog=pubs;Use ID=sa;Password=aaaa";
SqlConnection conn = new SqlConnection(connstr);
string sqlstr ="select user,pwd from login where user='" + userName + "'and pwd='" + password + "'";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
string temp="";
while (sdr.Read())
{
temp="yes";
Response.Write("1111111111111有没有进来过");
}
sdr.Close();
if (temp=="yes")
{
userTb.Text = "";
pwdTb.Text = "";
Response.Write("222222222222222有没有进来过");
Response.Redirect("http://www.sina.com.cn");
}
else
{
Response.Write("<script>alert('您的用户名或密码有错误!');</script>");
userTb.Text = "";
pwdTb.Text = "";
}
conn.Close();
还有我数据库是在 服务器资源管理器--->数据连接---->(右击)创建新SQL Server数据库 里建的.不知在那里建对不对?