/// <summary> /// Loads the grid and column list controls according to the specified query /// </summary> /// <param name="sSQL"></param> private void LoadQueryRecords(string sSQL) { if (sSQL.Trim() == string.Empty) { MessageBox.Show("The SQL query was empty! Please enter a valid SQL query!"); return; } try { Cursor.Current = Cursors.WaitCursor; m_TableInfo = DatabaseUtilities.LoadDataTable(m_sSqlConnectionString, cmbDatabases.Text, sSQL); dgTableInfo.DataSource = m_TableInfo; // load the list of columns to include in the generator chklstIncludeFields.Items.Clear(); foreach (DataColumn col in m_TableInfo.Columns) { // exclude the primary/auto-increment key by default, but select/check all the others chklstIncludeFields.Items.Add(col.ColumnName, (chklstIncludeFields.Items.Count > 0)); } } catch (Exception ex) { MessageBox.Show("LoadQueryRecords error: " + ex.Message); } finally { Cursor.Current = Cursors.Default; UpdateControls(); } }
private void cmbDatabases_SelectedIndexChanged(object sender, EventArgs e) { if (cmbDatabases.SelectedIndex < 0) { return; } // user selected a different database, so load the table combobox try { Cursor.Current = Cursors.WaitCursor; cmbTables.DataSource = null; cmbTables.Items.Clear(); cmbTables.DisplayMember = "TableSchemaAndName"; cmbTables.ValueMember = "TableSchemaAndName"; DataTable dt = DatabaseUtilities.GetDatabaseTables(m_sSqlConnectionString, cmbDatabases.Text); cmbTables.DataSource = dt; } catch (Exception ex) { MessageBox.Show("cmbDatabases_SelectedIndexChanged error: " + ex.Message); } finally { Cursor.Current = Cursors.Default; UpdateControls(); } }
/// <summary> /// Initializes the database combobox control /// </summary> private void InitializeDatabaseControls() { try { Cursor.Current = Cursors.WaitCursor; cmbDatabases.DataSource = null; cmbDatabases.Items.Clear(); cmbTables.DataSource = null; cmbTables.Items.Clear(); // clear the tables also since they'll be invalid cmbDatabases.DisplayMember = "DATABASE_NAME"; cmbDatabases.ValueMember = "DATABASE_NAME"; DataTable dt = DatabaseUtilities.GetDatabases(m_sSqlConnectionString); cmbDatabases.DataSource = dt; } catch (Exception ex) { MessageBox.Show("Error loading database-tables into list: " + ex.Message); } finally { Cursor.Current = Cursors.Default; UpdateControls(); } }