我正在尝试开发控制台应用程序,我需要知道所有数据库列表名称。但是此代码不起作用。这是我的代码:
public static List<string> AllNpgsqlDatabaseName()
{
List<string> li = new List<string>();
NpgsqlConnection connection = new NpgsqlConnection("Host=localhost;Username=root;Password=root;");
connection.Open();
NpgsqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT name from sys.databases";
NpgsqlDataReader Reader;
Reader = command.ExecuteReader();
while (Reader.Read())
{
string row = "";
for (int i = 0; i < Reader.FieldCount; i++)
row += Reader.GetValue(i).ToString() + ", ";
li.Add(row);
}
connection.Close();
return li;
}
答案 0 :(得分:1)
您可以运行
SELECT datname FROM pg_database