1.装好Postgres

2.开启远程访问

配置postgresql.conf文件

listen_addresses = '*' 

配置pg_hba.conf文件

host    all         all         0.0.0.0/0          trust

3.下载npgsql 引用2个dll

使用Npgsql连接Postgres

4.code

 

  string strConn = ConfigurationManager.ConnectionStrings["npgsql"].ConnectionString;
            var conn = new NpgsqlConnection(strConn);

            string sql = "select * from test";
            var dt = new DataTable();

            var cmd = new NpgsqlDataAdapter(sql, conn);

            cmd.Fill(dt);

            foreach (DataRow row in dt.Rows)
            {
                Console.WriteLine(row["xxxx"].ToString());
            }
            conn.Close();
            Console.Read();

相关文章:

  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-04-21
猜你喜欢
  • 2021-11-25
  • 2021-08-03
  • 2021-10-26
  • 2021-12-26
  • 2022-02-06
  • 2021-11-24
  • 2021-12-02
相关资源
相似解决方案