MySQL and the GetSchema method

  • Thread starter Thread starter nathan.gomez
  • Start date Start date
N

nathan.gomez

Thanks for your time.

I've been trying to get a list of databases available on a mySQL server
(local) using the OdbcConnection.GetSchema() function. Thus far I have
only been able to get "views". Can anyone help me out?

code:
OdbcConnection c = new OdbcConnection();
c.ConncetionString = conString; // the connection works fine, so I have
not bothered to add it
c.open();

DataTable t = c.GetSchema(); // At this point I have seen people use
the "Databases"
// arg but it tells me
that there is no such collection.

How can I get the list of available databases? I know that it can't be
all that difficult, but I just can't seem to figure it out.

Using .NET 2.0 and SharpDevelop (I also have VS 2005 and I could use a
SQL server if need be, but I wanted to give mySQL and SharpDevelop a
try)
 
I have solved the issue. For those interested parties:
public string retreiveDatabases() // The OdbcConnection has already
been made
{
string databases = "";
try
{
tempQuery = "show databases;";
data = new DataSet(); //
This is declared elsewhere.
da = new OdbcDataAdapter(tempQuery, conn); // This is also
declared elsewhere
da.Fill(data);
DataRow row;
for(int i = 0; i < data.Tables[0].Rows.Count; i ++)
{
row = data.Tables[0].Rows;
databases += (string)row[0] + "|"; // i'm using a .Split
on the calling method
}
return databases;
}
catch(Exception exc)
{
MessageBox.Show(exc.Message, "Error");
return "Could not load the database information!";
}
}

This works. It was just way too simple. I have been wresting with
this in my spare time for two days now, and I don't knwo how I
overlooked this. It's not like I didn't know the command! Oh well,
hopefully, someone can learn from my foolishness.
 
Back
Top