Beispiel #1
0
 private void tableBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     //загружаем все поля выбранной таблицы
     if (tableBox.SelectedItem != null)
     {
         fieldLabel.Visibility  = Visibility.Visible;
         fieldBox.Visibility    = Visibility.Visible;
         labelBinary.Visibility = Visibility.Visible;
         binList.Visibility     = Visibility.Visible;
         string _table = tableBox.SelectedItem.ToString();
         _tableName = _table;
         string _catalog = dbListBox.SelectedItem.ToString();
         FieldsClass.ClearList();
         condGrid.Items.Refresh();
         using (SqlConnection conn = new SqlConnection(connectionBox.Text + "Initial Catalog =" + _catalog))
         {
             try
             {
                 conn.Open();
                 string[] restrictions = new string[4];
                 restrictions[2] = _table;
                 DataTable     table  = conn.GetSchema("Tables", restrictions);
                 string        sql    = "SELECT * FROM " + _table + " WHERE 1 = 0";
                 SqlCommand    cmd    = new SqlCommand(sql, conn);
                 SqlDataReader reader = cmd.ExecuteReader();
                 DataTable     schema = reader.GetSchemaTable();
                 fieldBox.Items.Clear();
                 binList.Items.Clear();
                 for (int i = 0; i < schema.Rows.Count; i++)
                 {
                     if (schema.Rows[i][0] != null)
                     {
                         FieldsClass.AddValue(schema.Rows[i][0].ToString(), "");
                         fieldBox.Items.Add(schema.Rows[i][0].ToString());
                         binList.Items.Add(schema.Rows[i][0].ToString());
                     }
                 }
             }
             catch (Exception error)
             {
                 MessageBox.Show(error.ToString());
             }
             finally
             {
                 conn.Close();
             }
         }
     }
     else
     {
         fieldLabel.Visibility  = Visibility.Hidden;
         labelBinary.Visibility = Visibility.Hidden;
         fieldBox.Visibility    = Visibility.Hidden;
         binList.Visibility     = Visibility.Hidden;
     }
 }
Beispiel #2
0
        private void dbListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            fieldBox.Items.Clear();
            binList.Items.Clear();
            tableBox.Items.Clear();
            byteData = null;
            FieldsClass.ClearList();
            condGrid.Items.Refresh();
            tablesLabel.Visibility = Visibility.Visible;
            tableBox.Visibility    = Visibility.Visible;
            ComboBox comboBox = (ComboBox)sender;
            string   _table   = comboBox.SelectedItem.ToString();

            _tableCatalog = _table;
            using (SqlConnection conn = new SqlConnection(connectionBox.Text + "Initial Catalog =" + _table))
            {
                try
                {
                    conn.Open();
                    allColumnsSchemaTable = conn.GetSchema("Tables");
                    List <string> tablesList = ShowCols(allColumnsSchemaTable, "TABLE_NAME");
                    foreach (string cur in tablesList)
                    {
                        tableBox.Items.Add(cur);
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }
        }