C#操作PostgreSQL演示代码片段

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

先到网上下载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());
 
            }