Example #1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            string serverURI = uri_form.Text;
            string user_cred = user_form.Text;
            string pass_cred = pass_form.Password;
            string db        = db_form.Text;

            sql_object sqlobj = new sql_object();

            sqlobj.login    = user_cred;
            sqlobj.password = pass_cred;
            sqlobj.uri      = serverURI;
            sqlobj.database = db;

            myConnectionString = $"server={serverURI};uid={user_cred};" +
                                 $"pwd={pass_cred};database = {db};";

            try
            {
                //testing connection for login before proceeding
                conn = new MySql.Data.MySqlClient.MySqlConnection();
                conn.ConnectionString = myConnectionString;
                conn.Open();
                editor_window win2 = new editor_window(sqlobj);
                win2.Show();
                this.Close();
            } catch (MySql.Data.MySqlClient.MySqlException ex) {
                MessageBox.Show(ex.Message);
            }
        }
        public editor_window(sql_object sqlobj)
        {
            InitializeComponent();
            myConnectionString = $"server={sqlobj.uri};uid={sqlobj.login};" +
                                 $"pwd={sqlobj.password};database = {sqlobj.database};";
            try
            {
                conn = new MySql.Data.MySqlClient.MySqlConnection();
                conn.ConnectionString = myConnectionString;
                conn.Open();
                MySqlCommand command = conn.CreateCommand();
                command.CommandText = "SHOW TABLES;";
                MySqlDataReader Reader;
                Reader = command.ExecuteReader();
                while (Reader.Read())
                {
                    string row = "";
                    for (int i = 0; i < Reader.FieldCount; i++)
                    {
                        row += Reader.GetValue(i).ToString();
                    }
                    table_comboBox.Items.Add(row);
                }

                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }