1,Postgresql
string sql = "Host=**;Port =5432; Username=**;Password=**;Database=**;";
NpgsqlConnection conn = new NpgsqlConnection(sql);
NpgsqlCommand cmd =conn.CreateCommand();
cmd.CommandText = $"SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg%' AND tablename NOT LIKE 'sql_%' ORDER BY tablename";
conn.Open();
NpgsqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string id = dr[0].ToString();//表名
}
}
2,Mysql
string sql = "Host=**;Port =**; Username=**;Password=**;Database=**;";
MySqlConnection conn = new MySqlConnection(sql);
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = $"select table_name from information_schema.tables where table_schema='库名'";
conn.Open();
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string id = dr[0].ToString();
}
}