网站登录界面遇到的小问题,求助大神!!!
c#吧
全部回复
仅看楼主
level 9
依西子 楼主
这是登录界面点击登录按钮下的代码,但运行起来后,输入用户名和密码 ,会显示“对不起,您的用户名或密码不正确,请核对!”,密码没有错误,再点击一下就可以登录成功。这是为什么?求大神解决
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection();
SqlCommand mycmd = new SqlCommand();
string mystr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=E:\\练习\\通用权限管理系统\\通用权限管理系统\\Database1.mdf;Integrated Security=True;User Instance=True";
myconn.ConnectionString = mystr;
myconn.Open();
string name, password, sqlstr, userExist = "";
name = TextBox4.Text;
password = TextBox1.Text;
sqlstr = "select user_password from [user] where user_name='" + name + "' and user_password='" + password + "'";
mycmd.Connection = myconn;
mycmd.CommandText = sqlstr;
try
{
userExist = mycmd.ExecuteScalar().ToString();
}
catch (Exception ex)
{
Label1.Text = "对不起,您的用户名或密码不正确,请核对!";
}
2014年06月02日 04点06分 1
level 12
为什么不用dataset 然后判断select出来的数据是否count大于0
2014年06月02日 04点06分 2
不会写代码
2014年06月02日 06点06分
回复 依西子 :网上到处都是,查下吧,数据绑定dataset 然后判断count
2014年06月02日 06点06分
level 14
SqlCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "select.....";
myConnection.Open();
SqlDataAdapter myDataReader = new SqlDataAdapter();
myDataReader.SelectCommand = myCommand;
DataSet ds = new DataSet();
myDataReader.Fill(ds);
myConnection.Close();
myConnection.Dispose();
return ds;
2014年06月02日 06点06分 3
1