所以这是我的问题。我有一个名为 Login 的类,它将用于登录和创建新的登录帐户。
我创建了一个不带参数的登录构造函数
public Login()
{
_gloID = 0;
_Username = null;
_Password = null;
_Note = null;
_Active = false;
_Status = null;
_gvoID = 0;
_DateModified = new DateTime(1901, 1, 1);
_ModifiedBy = 0;
}
我还创建了一个带有两个参数的 Login 构造函数。此构造函数获取用户名和密码,然后从数据库中收集其余信息。
public Login(string username, string password)
{
// Declarations
uint gloid = 0, gvoid = 0, modifiedby = 0;
string note = null, status = null;
bool active = false;
DateTime datemodified = new DateTime(1901, 1, 1);
// Command
string query = string.Format("SELECT glo_id, glo_note, glo_active, glo_status, gvo_id, date_modified, modified_by FROM gfrc_login" +
" WHERE glo_username = '{0}' AND glo_password = '{1}'", username, password);
try
{
using (conn)
{
conn.Open();
cmd = new OleDbCommand(query, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
gloid = Convert.ToUInt32(rdr.GetString(0));
note = rdr.GetString(1).ToString();
active = Convert.ToBoolean(rdr.GetString(2));
status = rdr.GetString(3).ToString();
gvoid = Convert.ToUInt32(rdr.GetString(4));
datemodified = Convert.ToDateTime(rdr.GetString(5));
modifiedby = Convert.ToUInt32(rdr.GetString(6));
}
}
}
finally
{
if (rdr != null)
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
_gloID = gloid;
_Username = username;
_Password = password;
_Note = note;
_Active = active;
_Status = status;
_gvoID = gvoid;
_DateModified = datemodified;
_ModifiedBy = modifiedby;
}
请注意,所有数据库连接变量都已在类的开头声明。
现在,当我尝试运行以下命令时,我收到一条错误消息:“登录”不包含带有 2 个参数的构造函数。
protected void Login_Authenticate(object sender, EventArgs e)
{
string username = txtUsername.Text;
string password = CalculateMD5(txtPassword.Text);
Login login = new Login(username, password);
}
编辑:仅供参考,我在我的其余代码中采取了防止 SQL 注入的措施。