0
I have an application in C# that performs a search. For this is used a field called 'status' that is no longer a list in a combobox. I need it to appear beyond the status that comes from the bank, a status called 'ALL' that does not exist in the bank, and if possible that it gets first on the combobox when listing. Follow my code to list the fields.
String string_conn = ConfigurationManager.ConnectionStrings["conexao"].ConnectionString;
NpgsqlConnection conn = new NpgsqlConnection(string_conn);
try
{
conn.Open();
}
catch (NpgsqlException sqle)
{
MessageBox.Show("Falha ao efetuar a conexão. Erro: " + sqle);
}
String sql = "SELECT * FROM usuario";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
DataTable dtResultado = new DataTable();
dtResultado.Clear();
da.Fill(dtResultado);
Invoke((MethodInvoker)delegate
{
CbUsuario.DataSource = null;
CbUsuario.DataSource = dtResultado;
CbUsuario.ValueMember = "cod";
CbUsuario.DisplayMember = "nome";
CbUsuario.SelectedItem = "";
CbUsuario.Refresh();
});
conn.Close();
in the
CbUsuario
you want to add the status "all"?– Barbetta
first, show how you are filling the Status combo... then take a look at this answer I just put, you can greatly improve your code: https://answall.com/a/311774/69359 (in the example you have Oledb, but you have all the respective classes for Npgsql)
– Rovann Linhalis
this, is so that when I go to make a query selecting ALL it brings all the results, on the contrary it brings only what this selected.
– Ralf