0
Code that loads the 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 rode the select
to concatenate what I need to show in the combobox, but I don’t know how to inform in the DisplayMember
. The way it is, when I run the program it loads the combobox with the following value: System.Data.DataRowView
.
Gee, young man. I want to help you, but there’s so much bad in there that I don’t even know where to start.
– Jéf Bueno
kkk I am aware of this.. you are not the first to say this :( but help me there.. because the select is correct, tested in the bank.. just in time to show that you’re fucked up..
– WSS
then...
this.Load += new System.EventHandler(this.frmAdicionarProdutos_Load);
inside the event itself I’ve never seen...it’s good that the load only runs once right... on the other 'bad' things I will consider that it is only your tests and that this will not go to the final result (hopefully) hehe vlw– Rovann Linhalis
It is not duplicated, there was doubt of how to load, here is doubt of how to show the concatenated items..
– WSS