SqlDataReader使用问题
我想写的是一个登录判断问题
string st_connstr = ConfigurationManager.ConnectionStrings[ "STUDENTS.MDFConnectionString "].ConnectionString;
SqlConnection myConnection = new SqlConnection(st_connstr);
string sqlstr = "select User_Password, User_Power from uers where User_ID= ' " + txbName.Text + " ' ";
SqlCommand mySqlCommand = new SqlCommand(sqlstr,myConnection);
myConnection.Open();
SqlDataReader reader = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
if (txbPassWord.Text == reader[ "User_Password "].ToString() && reader[ "User_Power "].ToString() == "1 ")
{
Response.Redirect( "ST_student.aspx ");
}
else if (txbPassWord.Text == reader[ "User_Password "].ToString() && reader[ "User_Power "].ToString() == "用户 ")
{
Response.Redirect( "ST_query.aspx ");
}
}
Response.Write( "用户名或密码错误! ");
如果只是判断密码,是可以的
但加了判断权限的代码:
&& reader[ "User_Power "].ToString() == "用户 "
就不对了
------解决方案--------------------数据库里怎么写的?
------解决方案--------------------都加这个 去掉前后空格
例如
txbPassWord.Text.Trim() == reader[ "User_Password "].ToString().Trim()
------解决方案--------------------jf
------解决方案--------------------我在数据库存里面,一般都用varchar类型,所以很少用到去空格.
------解决方案--------------------你这个你试下用 ' or '0 '= '0为帐号密码登录下