From 74202e8d091886e703af302dff8ee59560d1f85a Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 12 Oct 2018 20:59:25 +0200 Subject: Listing MySQL DBs --- kurier/Form1.Designer.cs | 1 + kurier/Form1.cs | 16 ++++++++++++++++ kurier/MySQL.cs | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/kurier/Form1.Designer.cs b/kurier/Form1.Designer.cs index 41ac97b..47549f4 100644 --- a/kurier/Form1.Designer.cs +++ b/kurier/Form1.Designer.cs @@ -49,6 +49,7 @@ // // cbDatabaseName // + this.cbDatabaseName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbDatabaseName.FormattingEnabled = true; this.cbDatabaseName.Location = new System.Drawing.Point(89, 10); this.cbDatabaseName.Name = "cbDatabaseName"; diff --git a/kurier/Form1.cs b/kurier/Form1.cs index eb6ab88..a8bd7eb 100644 --- a/kurier/Form1.cs +++ b/kurier/Form1.cs @@ -5,6 +5,7 @@ using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; +using MySql.Data.MySqlClient; namespace kurier { @@ -29,11 +30,26 @@ namespace kurier { if (!MySQL.getConfigured()) (new MysqlSettings()).ShowDialog(); if (!MySQL.getConfigured()) this.Dispose(); + this.refreshDatabaseList(); } private void bSettings_Click(object sender, EventArgs e) { (new MysqlSettings()).ShowDialog(); + this.refreshDatabaseList(); + } + + internal void refreshDatabaseList() + { + this.cbDatabaseName.Items.Clear(); + MySQL c = new MySQL(""); + MySqlDataReader dbs = c.select("SELECT TABLE_SCHEMA FROM information_schema.COLUMNS GROUP BY TABLE_SCHEMA;"); + while (dbs.Read()) + { + this.cbDatabaseName.Items.Add(dbs.GetString(0)); + } + this.cbDatabaseName.SelectedIndex = 0; + dbs.Close(); } } } diff --git a/kurier/MySQL.cs b/kurier/MySQL.cs index cafb5c8..81a3a0b 100644 --- a/kurier/MySQL.cs +++ b/kurier/MySQL.cs @@ -61,6 +61,12 @@ namespace kurier return ""; } + public MySqlDataReader select(string query) + { + MySqlCommand comm = new MySqlCommand(query, conn); + return comm.ExecuteReader(); + } + public static string getHost() { return Properties.Settings.Default.HOST; } public static string getUser() { return Properties.Settings.Default.USER; } public static string getPass() { return Properties.Settings.Default.PASS; } -- cgit v1.2.3