I need to access a database where I put the data myself, the insert part is working, but now I need to "get" the data again when I click the button, so it does not matter what way I do it you always get this error message:
System.InvalidOperationException: 'ExecuteReader: Connection property has not been initialized.'
My code is in this form:
public void RetornaUser(string Service)
{
cmd = new SqlCommand("SELECT * from Logins WHERE Servico = @Service AND Estado = @Estado");
cmd.Parameters.AddWithValue("@Servico", Service);
cmd.Parameters.AddWithValue("@Estado", Estado);
con.Open();
SqlDataReader leitor = cmd.ExecuteReader();
while (leitor.Read())
{
//passo os valores para o objeto cliente
//que será retornado
string Login = leitor["Login"].ToString();
MessageBox.Show(Login);
}
//fecha conexão
con.Close();
}
If you want to see the whole code HERE
In the case I wanted to know how do I remove the data and move to a variable so that my function returns to the other account data for it to use.