使用Npgsql连接Postgres
1.装好Postgres
2.开启远程访问
配置postgresql.conf文件
listen_addresses = '*'
配置pg_hba.conf文件
host all all 0.0.0.0/0 trust
www.zzzyk.com
www.zzzyk.com
3.下载npgsql 引用2个dll
4.code
www.zzzyk.com
string strConn = ConfigurationManager.ConnectionStrings["npgsql"].ConnectionString;
var conn = new NpgsqlConnection(strConn);
var conn = new NpgsqlConnection(strConn);
string sql = "select * from test";
var dt = new DataTable();
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();
{
Console.WriteLine(row["xxxx"].ToString());
}
conn.Close();
Console.Read();