private void Search_Click(object sender, RoutedEventArgs e) { if (ColumnsComboBox.SelectedItem != null && SearchBox.Text != "") { string selectedDataBase = DatabaseSelect.SelectedItem.ToString(); string selectedColumn = ColumnsComboBox.SelectedItem.ToString(); string asterix = ""; string searchText; int length = SearchBox.Text.Length - 1; if (SearchBox.Text[0] == '*') { asterix = "%"; searchText = SearchBox.Text.Substring(1, length); } else { asterix = ""; searchText = SearchBox.Text; } string searchInstruction = " WHERE " + selectedColumn + " LIKE '" + asterix + searchText + "%'"; dt = ConnectSQL.GetData(selectedDataBase, searchInstruction); SQLDataGrid.ItemsSource = dt.DefaultView; foreach (var column in SQLDataGrid.Columns) { column.IsReadOnly = true; } SqlRecordsCount.Content = "Records : " + dt.Rows.Count.ToString(); } }
private void DatabaseSelect_SelectionChanged(object sender, SelectionChangedEventArgs e) { ColumnsComboBox.Items.Clear(); SQLDataGrid.Columns.Clear(); SearchBox.Text = ""; SQLDataGrid.ItemsSource = null; SqlRecordsCount.Content = null; string selectedDataBase = DatabaseSelect.SelectedItem.ToString(); dt = ConnectSQL.GetData(selectedDataBase, ""); foreach (DataColumn columnSQL in dt.Columns) { string columnName = columnSQL.ToString(); if (!columnSQL.ToString().ToUpper().Contains("USER") && !columnSQL.ToString().ToUpper().Contains("VOL")) { ColumnsComboBox.Items.Add(columnName); columnNames.Add(columnName); } } SQLDataGrid.ItemsSource = dt.DefaultView; }