下面的代码有什么问题?我的代码给我一些错误。我想在我们的项目上使用面向对象的程序,但是它不能正常工作。有人可以帮我解决我的问题
class Login
{
public string Username { get; set; }
public string Userpassword { get; set; }
public Login()
{
this.Username = user; //does not exist in the current context
this.Userpassword = pass; //does not exist in the current context
}
private void ClearTexts(string user, string pass)
{
user = String.Empty;
pass = String.Empty;
}
public void Login(string user, string pass)
{
int count = 0;
Connection connection = new Connection();
string sql = "SELECT * FROM tbl_Login";
MySqlConnection conn = new MySqlConnection(connection.ConnectionString);
MySqlCommand cmd = new MySqlCommand(sql, conn);
conn.Open();
MySqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Login Successfully!");
frmLogin.Hide(); //required for the non-static field,method
frmMain.showMe(this); //best overloaded method match...
}
else
{
txtPassword.Focus(); /does not exist in the current context
MessageBox.Show("Username or Password Is Incorrect");
txtUserName.Text = ""; //does not exist in the current context
txtPassword.Text = ""; //does not exist in the current context
}
connection.Close();
}
}
答案 0 :(得分:0)
您不需要没有参数的create class client extends v
构造函数。而是使用以下参数将字段设置下移至构造函数:
Login()
答案 1 :(得分:-1)
public Login(){
this.Username = user; //does not exist in the current context
this.Userpassword = pass; //does not exist in the current context
}
user
和pass
不是函数的参数,因此它们不存在。您已经有一个接受用户并通过的构造函数,因此此函数应将其设置为null或不存在,并强制使用user / pass构造函数