C#操作PostgreSQL9.2

C#操作PostgreSQL


先去下个PostgreSql.Data.PostgreSqlClient.dll的文件.(如果网上不好下,那去下个SharpMap,SharpMap.Extensions这个文件夹里面有)

然后添加引用,使用命名空间

using PostgreSql.Data.PostgreSqlClient;

然后
          string connectString = @"Server=localhost;Database=test;UserID=test;Password=test";

            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())

                                        this.richTextBox1.Text += reader[0].ToString()+"\n";

            }

原文地址:https://www.cnblogs.com/dview112/p/2736832.html