0
Answer

Need Help to connet to postgres database on .net enviroment

Natasha bronze

Natasha bronze

15y
2.9k
1
Hi,
I am presently working on visual studio 2005, and my back end is postgres, now i need some help with ado.net. I need to put my postgres table in a data grid view using c# in a windows form? rite now iam trying npgsql to connect it with DB.. but iam not getting the rite outcome. here is the code which iam using.. could some one help me with this?

NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432; User ID= postgres; Password= postgres; database= postgres");
            string query = "Select * from EMP";
            NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
           
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, conn);
            //NpgsqlCommandBuilder cbuilder = new NpgsqlCommandBuilder(da);
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            da.Fill(dt);

            DataGridView dg = new DataGridView();
            dg.DataSource = dt;