I'm trying through this code:
private void frmAdicionarProdutos_Load(object sender, EventArgs e)
{
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 PRODUTOS.ID_PRODUTO, PRODUTOS.NOME, PRODUTOS.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();
}
}
}
At first I want to just test this way, then implement calling the class of the bank.
This code does not show anything in the ComboBox, I think I forgot something .. Well I would like to show: Product name + value of it (concatenated).