-1
C# and Mysql
I’m trying to get the table values Employees of the current user logged into the program and displayed in the Windows of my form, however the values are not being returned, my guess is that the function dataReader.Read() is not returning anything.
My code:
private void FormUsuario_Load(object sender, EventArgs e)
{
LimparCampos();
PreencherCampos();
}
private void PreencherCampos()
{
Form1 f = new Form1();
Conexao objCon = new Conexao();
string query = "select * from funcionarios WHERE Nome = '" + f.username + "' AND Senha = '" + f.password + "'";
MySqlCommand cmd = new MySqlCommand(query, objCon.Conectar());
try
{
objCon.Open();
MySqlDataReader dataReader;
dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
lbl_nome.Text += dataReader.GetString("Nome");
lbl_senha.Text += dataReader.GetInt32("Senha");
lbl_cargo.Text += dataReader.GetString("Cargo");
lbl_cpf.Text += dataReader.GetString("CPF");
lbl_telefone.Text += dataReader.GetString("Telefone");
lbl_endereco.Text += dataReader.GetString("Endereco");
MessageBox.Show("Dados atualizados com sucesso");
}
}
catch (MySqlException er)
{
MessageBox.Show("Erro de conexão: " + er);
}
}
private void LimparCampos()
{
lbl_nome.Text = string.Empty;
lbl_senha.Text = string.Empty;
lbl_cargo.Text = string.Empty;
lbl_cpf.Text = string.Empty;
lbl_telefone.Text = string.Empty;
lbl_endereco.Text = string.Empty;
}