列名 'XMMCS' 无效。
public static void USER_CHECKER(string strLogin_Name, string strPassWord)
{
SqlDataReader dtr;
SqlConnection conMy = DBCONN.GetDBConn();
string szQuery;
szQuery = "SELECT t1.Employee_Name, t1.XMMCS,t2.EmpID, t2.PassWord, t2.RoleID FROM T_System_Role t3,T_System_USER t2,T_System_EMPLOYEE t1 where t2.EmpID = t1.Employee_ID";
szQuery = szQuery + " and t2.EmpID='" + strLogin_Name.Replace("'","''") + "' and t2.state=0 and t3.Role_ID=t2.RoleID and t3.state=0";
//SqlCommand cmdMy = new SqlCommand("SELECT * FROM T_System_USER WHERE Login_Name = '" + strLogin_Name + "'", conMy);
SqlCommand cmdMy = new SqlCommand(szQuery, conMy);
cmdMy.Connection.Open();
dtr = cmdMy.ExecuteReader();
if (dtr.Read()) //如果用户名存在,验证密码
{
if (strLogin_Name == dtr["EmpID"].ToString() && strPassWord == dtr["PassWord"].ToString()) //如果用户名和密码正确
{
HttpContext.Current.Session["LoginUserID"] = strLogin_Name;
HttpContext.Current.Session["XMMCS"] = dtr["XMMCS"].ToString();
HttpContext.Current.Session["LoginUserName"] = dtr["Employee_Name"].ToString();
HttpContext.Current.Session["RoleID"] = dtr["RoleID"].ToString();
HttpContext.Current.Session["PageSize"] = System.Configuration.ConfigurationManager.AppSettings.Get("PageSize").ToString();
dtr.Close();
cmdMy.Connection.Close();
System.Web.HttpContext.Current.Response.Redirect("main.aspx");
dtr.Close();
cmdMy.Connection.Close();
}
else //如果密码不正确
{
dtr.Close();
cmdMy.Connection.Close();
VerifyThree();
}
}
else //如果用户名不存在
{
dtr.Close();
cmdMy.Connection.Close();
VerifyThree();
}
}
------解决方案--------------------dtr["XMMCS"].ToString(); 字段写错了把!对比下数据库是否一样!
如果真不行,建议你换做下标来,性能也比你这样好!
dtr[0].ToString();
------解决方案--------------------提示的这么明显了,列名无效!
检查T_System_EMPLOYEE表中是否有XMMCS这个字段??或者是字段名称你写错了??
------解决方案--------------------T_System_EMPLOYEE表里字段名写错没?