无法将类型“object”隐式转换为“bool”。存在一个显式转换(是否缺少强制转换?)
代码如下:usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingSys...
代码如下:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String strSQL = "", strConn = "";
strConn = "Data Source=.;Initial Catalog=kcgl;Persist Security Info=True;User ID=sa;Password=sql2005";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
strSQL = "select Pid,Ppassword from Ptyh where Pid='" + TextBox1.Text + "'and Ppassword='" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["Pid"] = TextBox1.Text;
if (Session["Ppassword"] = TextBox2.Text) //问题在这里!!!!
{
Response.Write("<script>alert('登录成功!');location.href='main.aspx';</script>");
}
else
{
Response.Write("<script>alert('密码错误,请重新登录!');location.href='login.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('用户名错误,请重新登录!');location.href='login.aspx';</script>");
conn.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
}
} 展开
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String strSQL = "", strConn = "";
strConn = "Data Source=.;Initial Catalog=kcgl;Persist Security Info=True;User ID=sa;Password=sql2005";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
strSQL = "select Pid,Ppassword from Ptyh where Pid='" + TextBox1.Text + "'and Ppassword='" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["Pid"] = TextBox1.Text;
if (Session["Ppassword"] = TextBox2.Text) //问题在这里!!!!
{
Response.Write("<script>alert('登录成功!');location.href='main.aspx';</script>");
}
else
{
Response.Write("<script>alert('密码错误,请重新登录!');location.href='login.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('用户名错误,请重新登录!');location.href='login.aspx';</script>");
conn.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
}
} 展开
1个回答
展开全部
改成 Session["Ppassword"] == TextBox2.Text
(赋值和判断这么简单的问题你怎么都看不出来)
(赋值和判断这么简单的问题你怎么都看不出来)
更多追问追答
追问
哦哦,没看到
改了之后,不管是密码错误还是用户名错误,提示的都是用户名错误,这是怎么回事?
追答
strSQL = "select Pid,Ppassword from Ptyh where Pid='" + TextBox1.Text + "'and Ppassword='" + TextBox2.Text + "'";
这句代表的选择Pid=用户名框,Ppassword=密码框的条目吧
这样的话,岂不是只有当用户名和密码都匹配上,dr才会给出条目(dr.Read()为真)
于是就不可能出现用户名正确且密码错误的情况了,通通会变成else -> 用户名错误
所以从我的角度看,似乎要把 and Ppassword 字段删去才对
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询