使用C#连结PgSQL并且列出指定DB内的所有资料表名称


 

资料来源: http://jashliao.pixnet.net/blog/post/206258848

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Npgsql;//Ó£gULO!usÓ£greOiDUoPNMq

namespace CS_Console_PgSQL

{

    class Program

    {

        static
void Pause()

        {

 

            Console.Write(“Press any key to continue . . . “);

 

            Console.ReadKey(true);

 

        }

        static
void Main(string[]
args)

        {

            NpgsqlConnection
conn = new NpgsqlConnection(“Server=127.0.0.1;Port=5432;User
Id=postgres;Password=postgres;Database=v7;”
);

            conn.Open();

            NpgsqlCommand
command = new NpgsqlCommand(“SELECT table_name FROM information_schema.tables
WHERE table_schema = ‘public'”
, conn);

            try

            {

                NpgsqlDataReader
reader = command.ExecuteReader();

 

                while
(reader.Read())

                {

                    string
shop = reader[0].ToString(); ;

                    Console.WriteLine(shop);

                }

            }

            finally

            {

                conn.Close();

                Pause();

            }

        }

    }

}

 


 


相关文章