Zi 字媒體
2017-07-25T20:27:27+00:00
使用C#連結PgSQL並且列出指定DB內的所有資料表名稱
資料來源: http://jashliao.pixnet.net/blog/post/206258848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Npgsql;//接Ó£g下U來LO說!明u連s接Ó£g字r串e所O表i示DU的o意PN義Mq
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();
}
}
}
}
寫了
5860316篇文章,獲得
23313次喜歡