468,101 Members | 1,344 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

MySQL and the GetSchema method

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)

Aug 22 '06 #1
1 5988
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[i];
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.

Aug 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Brian Keating | last post: by
Atli
6 posts views Thread by Atli | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.