Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- string sql = "SELECT * FROM " + textBox51.Text; // Строка запроса
- MySqlConnection connection = new MySqlConnection(connStrMySql);
- connection.Open();
- #region *** ДОБАВЛЕНИЕ ЗАПИСИ В ТАБЛИЦУ ***
- #region *** ПЕРЕМЕННАЯ ***
- int s; // СТАРТ. ПОЗИЦИЯ С КОТОРОЙ НУЖНО НАЧИНАТЬ ДОБАВЛЯТЬ ЗАПИСИ
- s = Convert.ToInt32(textBox55.Text);
- int f; // ФИНИШ. ПОЗИЦИЯ НА КОТОРОЙ НУЖНО ЗАКОНЧИТЬ ДОБАВЛЯТЬ ЗАПИСИ
- f = Convert.ToInt32(textBox56.Text);
- int r = f - s; // КОЛ. КОЛИЧЕСТВО ПОЗИЦИЙ, КОТОРОЕ ТРЕБУЕТСЯ ДОБАВИТЬ
- int otkl = s + 1000;
- #endregion *** ПЕРЕМЕННАЯ ***. КОНЕЦ ХХХ
- for (s = Convert.ToInt32(textBox55.Text); s <= f; s++) //
- {
- pol_2 = s;
- int col;
- col = Convert.ToInt32(textBox59.Text);
- for (int pol_3 = 1; pol_3 <= col; pol_3++) //
- {
- MySqlCommand sqlCom = new MySqlCommand
- ("INSERT INTO " + textBox51.Text + // ТАБЛИЦА
- "(" + textBox52.Text + // ПОЛЯ
- ") VALUES"
- + "('"
- +
- pol_1 + "', '" + pol_2 + "', '" + pol_3 + "', '" + pol_4 + "', '" + pol_5 + "', '" + pol_6 + "', '" + pol_7 + "', '" + pol_8 + "', '" + pol_9 + "', '" + pol_10 + "', '" + pol_11 + "', '" + pol_12 + "', '" + pol_13 + "', '" + pol_14 + "', '" + pol_15 + "', '" + pol_16 + "', '" + pol_17
- +
- "')",
- connection); // РАБОТАЕТ. ПОДСТАВЛЯЕТСЯ значение из переменных
- sqlCom.ExecuteNonQuery();
- }
- if (s == otkl)
- {
- connection.Close();
- connection.Open();
- otkl = s + 1000;
- }
- }
- MessageBox.Show("Добавлено " + r + " записей ");
- return;
- }
- catch (Exception ex)
- {
- richTextBox1.Text += "!" + "rn";
- richTextBox1.Text += "ОШИБКА" + "rn";
- textBox1.AppendText("! " + "rn");
- textBox1.AppendText("ОШИБКА ХХХ " + "rn");
- MessageBox.Show(ex.ToString());
- MessageBox.Show("ОШИБКА ХХХ ");
- return;
- }
- private void insertData()
- {
- string conStr = "server=127.0.0.1;user=root;" +
- "database=test;password=123;";
- using (MySqlConnection con = new MySqlConnection(conStr))
- {
- try
- {
- string sql = "INSERT INTO friends (name, lastname, age)" +
- "VALUES (@Name, @LastName, @Age);";
- con.Open();
- MySqlCommand cmd = new MySqlCommand(sql, con);
- //создаем параметры и добавляем их в коллекцию
- cmd.Parameters.AddWithValue("@Name", "Vasya");
- cmd.Parameters.AddWithValue("@LastName", "Pupkin");
- cmd.Parameters.AddWithValue("@Age", 18);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement