1.装好Postgres
2.开启远程访问
配置postgresql.conf文件
代码语言:javascript复制listen_addresses = '*'
配置pg_hba.conf文件
代码语言:javascript复制host all all 0.0.0.0/0 trust
3.下载npgsql 引用2个dll
4.code
代码语言:javascript复制 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();