我有这些类,我想用它来登录,检查电子邮件和密码是否相同,然后它将重定向到相应的页面。
public class Account
{
public Account(){}
public int accID { get; set; }
public string emailAddress { get; set; }
public string password { get; set; }
public string name { get; set; }
public string company { get; set; }
public string position { get; set; }
public string department { get; set; }
public string mobileNo { get; set; }
public string officeNo { get; set; }
}
public static SADataReader DoSelectQuery(String sql)
{
SAConnection myConnection = new SAConnection(DB_STR);
//open the connection
myConnection.Open();
//Create a command object.
SACommand myCommand = myConnection.CreateCommand();
//Specify a query.
myCommand.CommandText = sql;
//Create a DataReader for the command
SADataReader reader = myCommand.ExecuteReader();
return reader;
}
public static List<Account> getAllAccountFromReader(SADataReader reader){
List<Account> results = new List<Account>();
while (reader.Read())
{
int accID = reader.GetInt32(0);
string emailAddress = reader.GetString(1);
string password = reader.GetString(2);
string name = reader.GetString(3);
string company = reader.GetString(4);
string position = reader.GetString(5);
string department = reader.GetString(6);
string mobileNo = reader.GetString(7);
string officeNo = reader.GetString(8);
Account Accounts = new Account();
Accounts.accID = accID;
Accounts.emailAddress = emailAddress;
Accounts.password = password;
Accounts.name = name;
Accounts.company = company;
Accounts.position = position;
Accounts.department = department;
Accounts.mobileNo = mobileNo;
Accounts.officeNo = officeNo;
results.Add(Accounts);
}
return results;
}
public static List<Account> getAllAccounts()
{
//Specify a query.
string sql = "SELECT accountID,emailAddress,password,name,company,position,department,mobileNo,officeNo FROM account";
SADataReader reader = DoSelectQuery(sql);
List<Account> results = getAllAccountFromReader(reader);
return results;
}
.CS 文件以检查字段
protected void btnSubmit_Click(object sender, EventArgs e)
{
string email = tbEmail.Text;
string password = tbPW.Text;
List<Account> getAccounts = MinuteDB.getAllAccounts();
// Session["getAllAccount"] = getAccounts;
if(email ==?? && password == ??)
{
//Session["name"] = name.ToString();
//Session["ID"] = Convert.ToInt32(accID.ToString());
Response.Redirect("HomePage.aspx");
}
else if (email == "" && password == "")
{
ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('Please enter Login and Password!');", true);
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('Wrong Login Or Password!');", true);
}
}
如何从 List getAccounts 中检索电子邮件和密码,以便我可以检查是否(电子邮件 ==来自列表帐户的电子邮件&& 密码 ==来自列表帐户的密码)?