Hello,,
I want to to check whether the Database is already exist in to the Specified Database server.. and also for table.. Is anybody knows the query for this?? i alreasy use the following query . but as the ExecuteNonQuery() only return the rows affeted by the Insert, Update and Delete query. Plz Help
query = "show tables from db_micro_structure;
com = new MySqlCommand(query, myConnection);
try
{
myConnection.Open();
MessageBox.Show(com.ExecuteNonQuery().ToString());
myConnection.Close();
}
catch
{
}
How to check whether database or table exist?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Jan MontanoRank #1,295 · 1.3K reputationPosted Dec 20, 2007, 4:11 PM EST
select * from information_schema.tables where table_name = tablename
In checking if your database exists... You have to catch it in your exception. Try to play around connecting with an existing database and a non-existing one. Then you'll get the exception it will throw if the database is non-existing.
I don't know if there's a better way to do database checking.
try abcRank #6,639 · 260 reputationPosted Dec 20, 2007, 7:31 PM EST
I am really thank ful for help me second time in query problem..