Sunteți pe pagina 1din 2

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Odbc;

namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

OdbcConnection conexiune;
DataSet dsDate;

private void Form1_Load(object sender, EventArgs e)


{
//deschide conexiune
OdbcConnection conexiune;
conexiune = new OdbcConnection();

conexiune.ConnectionString = "Driver={PostgreSQL
Unicode};database=postgres;server=localhost;port=5432;uid=postgres;pwd=sa15%2a2
9;sslmode=disable;readonly=0;protocol=7.4;fakeoidindex=0;showoidcolumn=0;rowversi
oning=0;showsystemtables=0;fetch=100;unknownsizes=0;maxvarcharsize=255;maxlong
varcharsize=8190;debug=0;commlog=0;usedeclarefetch=0;textaslongvarchar=1;unkno
wnsaslongvarchar=0;boolsaschar=1;parse=0;extrasystableprefixes=dd_;lfconversion=1;
updatablecursors=1;trueisminus1=0;bi=0;byteaaslongvarbinary=0;useserversideprepare
=1;lowercaseidentifier=0;gssauthusegss=0;xaopt=1";
conexiune.Open();

//incercam sa aducem date din baza de date


OdbcCommand comanda;
comanda = new OdbcCommand();
comanda.CommandText = "SELECT * FROM agent";
comanda.Connection = conexiune;
OdbcDataReader cititor;
cititor = comanda.ExecuteReader();
DataSet dsDate;
dsDate = new DataSet();
DataTable tblLocalitati;
tblLocalitati = new DataTable("Nume");
tblLocalitati.Load(cititor);
dsDate.Tables.Add(tblLocalitati);
//asignez coloanele din tabel catre combobox
this.cboClienti.DataSource = dsDate.Tables["Nume"];
this.cboClienti.DisplayMember = "numeprenume";
//stabilesc atributul cu valoare "utila"
this.cboClienti.ValueMember = "idagent";
conexiune.Close();
}
}
}