先到网上下载PostgreSql.Data.PostgreSqlClient.dll
然后添加引用,使用命名空间
using PostgreSql.Data.PostgreSqlClient; string connectString = @"Server=localhost;Database=postgres;User ID=arwen;Password=arwen"; PgConnection conn = new PgConnection(connectString); conn.Open(); PgCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from test"; cmd.CommandType = CommandType.Text; using (PgDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) Console.WriteLine(reader[0].ToString()); }