我在数据库中有两个表:
登录(LID,UName,UPasword,UserType_ID)
UserType(UserType_ID,UserType)
我需要验证username和usertype并为UserName(UName)创建一个会话变量。
以下是我尝试的代码,但它显示错误
Error 58 The type or namespace name 'UserInformation' could not be found (are you missing a using directive or an assembly reference?)
CODE
public string LogOn(UserInformation objLogOnUserInformation)
{
// ConnectionManager conCm = new ConnectionManager();
try
{
MySqlConnection con = conn.Open();
MySqlCommand cmd, cmdOne;
MySqlDataReader dr;
// SqlDataReader dr;
string _str = "U";
cmd = new MySqlCommand("select LID from Credentials", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
//checking user name is present in database
if (dr.GetValue(0).ToString() == objLogOnUserInformation.UserId)
{
dr.Close();
//retriving Password for the existing user
cmd = new MySqlCommand("select Pasword from login where LID='" + objLogOnUserInformation.UserId + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
//checking the password is matching with the database
if (dr.GetValue(0).ToString() == objLogOnUserInformation.Password)
{
dr.Close();
cmd = new MySqlCommand("select UserType_ID from login where LID='" + objLogOnUserInformation.UserId + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
//checking user type
if (dr.GetValue(0).ToString() == _str)
{
dr.Close();
cmdOne = new MySqlCommand("select UName from login where LID='" + objLogOnUserInformation.UserId + "'", con);
dr = cmdOne.ExecuteReader();
dr.Read();
objLogOnUserInformation.SessionUserName = dr.GetValue(0).ToString();
dr.Close();
//if usertype is customer, U is returned
Response.Redirect("gallery.aspx");
}
else
{
dr.Close();
cmdOne = new MySqlCommand("select UName from login where LID='" + objLogOnUserInformation.UserId + "'", con);
dr = cmdOne.ExecuteReader();
dr.Read();
objLogOnUserInformation.SessionUserName = dr.GetValue(0).ToString();
dr.Close();
//If usertype is Admin, A is returned
Response.Redirect("Reports.aspx");
}
}
}
else
{
return " Either User Name or Password is not Valid";
}
}
}
}
}
catch
{
}
}