Hello,
I am wondering how you can do this...
I need to get a list of databases after I connect to a MySQL server. To be included in this list the database needs to pass some criteria. Basically if the database has particular named tables I want to add this to the list. (My ultimate goal is to allow the user to select which database to connect to)
Thanks,
---Dave
Getting a list of databases on a MySQL server
Try
http://dev.mysql.com/doc/refman/5.0/en/ ... chema.html
Example
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = "tableToLookFor"
http://dev.mysql.com/doc/refman/5.0/en/ ... chema.html
Example
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = "tableToLookFor"
-
- Posts: 43
- Joined: Thu 19 Jun 2008 14:30
You can use the following code to get the list of databases stored on the server side and also to add a database to the list if it contains a table with the specified name:
List databasesList = new List();
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
DataTable table1 = connection.GetSchema("Databases");
foreach (DataRow row in table1.Rows) {
string dbName = row[0].ToString();
DataTable table2 = connection.GetSchema("Tables", new string[] { dbName, "TableToLookFor" });
if (table2.Rows.Count > 0)
databasesList.Add(dbName);
}
List databasesList = new List();
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
DataTable table1 = connection.GetSchema("Databases");
foreach (DataRow row in table1.Rows) {
string dbName = row[0].ToString();
DataTable table2 = connection.GetSchema("Tables", new string[] { dbName, "TableToLookFor" });
if (table2.Rows.Count > 0)
databasesList.Add(dbName);
}