public void Execute(ConnectionProvider provider) { string sql = TextBox.GetSelectionOrAllText(); if (sql == string.Empty) { return; } TabControl.Items.Clear(); var cmd = new SqlCmd(provider, sql); if (sql.IndexOf("select", StringComparison.CurrentCultureIgnoreCase) >= 0 && sql.IndexOf("insert", StringComparison.CurrentCultureIgnoreCase) < 0 && sql.IndexOf("update", StringComparison.CurrentCultureIgnoreCase) < 0 && sql.IndexOf("delete", StringComparison.CurrentCultureIgnoreCase) < 0 ) { try { StringBuilder builder = new StringBuilder(); var ds = cmd.FillDataSet(); int i = 1; foreach (DataTable dt in ds.Tables) { var tab = new TabItem { Header = $"Table {i++}", Content = dt.CreateDataGrid() }; TabControl.Items.Add(tab); builder.AppendLine($"{dt.Rows.Count} row(s) affected"); } DisplayMessage(builder.ToString()); } catch (SqlException ex) { DisplayMessage(ex.Message()); } catch (Exception ex) { DisplayMessage(ex.Message); } } else { try { int count = cmd.ExecuteNonQuery(); string message = $"{count} row(s) affected"; DisplayMessage(message); } catch (SqlException ex) { DisplayMessage(ex.Message()); } catch (Exception ex) { DisplayMessage(ex.Message); } } if (TabControl.HasItems) { (TabControl.Items[0] as TabItem).Focus(); } }