Code that loads comboBox
:
private void frmAdicionarProdutos_Load(object sender, EventArgs e)
{
this.Load += new System.EventHandler(this.frmAdicionarProdutos_Load);
string serverName = "localhost";
string port = "5432";
string userName = "postgres";
string password = "adm";
string databaseName = "GE";
NpgsqlConnection conn = null;
string ConnString = null;
ConnString = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
serverName, port, userName, password, databaseName);
using (conn = new NpgsqlConnection(ConnString))
{
conn.Open();
string cmdCarregar = String.Format("SELECT CONCAT(id_produto,' ', nome,' ', preco) FROM PRODUTOS;");
using (NpgsqlCommand cmd = new NpgsqlCommand(cmdCarregar, conn))
{
NpgsqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
cbProdutos.DisplayMember = "nome";
cbProdutos.ValueMember = "id_produto";
cbProdutos.DataSource = dt;
conn.Close();
}
}
}
I set select
to concatenate what I need to show in comboBox, but I do not know how to report in DisplayMember
. As it is, when I run the program it loads the comboBox with the following value: System.Data.DataRowView
.