Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void SqlSelect(object sqlcommand)
- {
- int i = 0;
- foreach (var database in SelectedItem)
- {
- using (NpgsqlConnection connect = new NpgsqlConnection(connectionString + "Database=" + database))
- try
- {
- connect.Open();
- NpgsqlCommand command = new NpgsqlCommand(sqlcommand.ToString(), connect);
- NpgsqlDataReader reader = command.ExecuteReader();
- if (reader.HasRows)
- {
- if (Tselect == sampling)
- {
- listBox1.Invoke((MethodInvoker)(() => listBox1.Items.Add(database)));
- }
- else
- {
- while (i != reader.VisibleFieldCount)
- {
- Invoke((MethodInvoker)delegate { dataGridView1.Columns.Add(reader.GetName(i), reader.GetName(i)); }, new object[] { });
- i++;
- }
- i = 0;
- foreach (DbDataRecord datarecord in reader)
- {
- Invoke((MethodInvoker)delegate { dataGridView1.Rows.Add(); }, new object[] { });
- for (int count = 0; count < reader.VisibleFieldCount; count++)
- {
- Invoke((MethodInvoker)delegate { dataGridView1.Rows[i].Cells[count].Value = datarecord[count].ToString(); }, new object[] { });
- }
- i++;
- }
- }
- }
- else
- {
- listBox2.Invoke((MethodInvoker)(() => listBox2.Items.Add(database)));
- }
- }
- catch (NpgsqlException e)
- {
- ++id;
- find_err_lbl.Text = string.Format("Ошибок: {0}", id);
- find_err_lbl.ToolTipText += database + Environment.NewLine;
- }
- finally
- {
- connect.Close();
- }
- Invoke((MethodInvoker)delegate { toolStripProgressBar1.Value++; }, new object[] { });
- Invoke(new SetToolStripDelegate(SetToolStrip), string.Format("Прогресс: {0}%", 100 * ++i / SelectedItem.Count));
- }
- execute.Invoke((MethodInvoker)(() => execute.Text = "Выполнить"));
- execute.Invoke((MethodInvoker)(() => execute.Click -= new EventHandler(secondAction)));
- execute.Invoke((MethodInvoker)(() => execute.Click += new EventHandler(firstAction)));
- Invoke(new SetToolStripDelegate(SetToolStrip), "Готово");
- _thread.ForEach(delegate (Thread thread)
- {
- thread.Abort();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment