Форум программистов, компьютерный форум, киберфорум
C# Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.67/3: Рейтинг темы: голосов - 3, средняя оценка - 4.67
2 / 2 / 4
Регистрация: 26.09.2016
Сообщений: 108
1

Оптимизация запросов в бд

06.10.2018, 20:49. Показов 595. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Нужна помощь специалиста оптимизировать код отправки запросов в БД (подскажите как что) а то работает отлично только страшный шибко
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 private void Teal_Click(object sender, EventArgs e)
        {
          
           try
            {
                string myConnection = System.Configuration.ConfigurationManager.ConnectionStrings["myDatabaseConnection"].ConnectionString;
                using (var MyConn2 = new MySqlConnection(myConnection))
                {
                    save.Text = "Сохранения сессии. Подождите";
                    var MyCommand2 = new MySqlCommand("UPDATE clients SET  Tema1_1=@Tema1_1, Tema1_2=@Tema1_2, Tema1_3=@Tema1_3, Tema1_4=@Tema1_4, Tema1_5=@Tema1_5, Tema1_6=@Tema1_6, Tema1_7=@Tema1_7, Tema1_8=@Tema1_8, 1_1_d=@1_1_d,1_2_d=@1_2_d,1_3_d=@1_3_d,1_4_d=@1_4_d,1_5_d=@1_5_d,1_6_d=@1_6_d,1_7_d=@1_7_d,1_8_d=@1_8_d,location=@location WHERE id=@id", MyConn2);
                    var MyCommand3 = new MySqlCommand("UPDATE clients SET  Tema2_1=@Tema2_1, Tema2_2=@Tema2_2, Tema2_3=@Tema2_3, Tema2_4=@Tema2_4, Tema2_5=@Tema2_5, 2_1_d=@2_1_d,2_2_d=@2_2_d,2_3_d=@2_3_d,2_4_d=@2_4_d,2_5_d=@2_5_d,location=@location WHERE id=@id", MyConn2);
                    var MyCommand4 = new MySqlCommand("UPDATE clients SET  Tema3_1=@Tema3_1, Tema3_2=@Tema3_2, Tema3_3=@Tema3_3, Tema3_4=@Tema3_4, Tema3_5=@Tema3_5,Tema3_6=@Tema3_6, 3_1_d=@3_1_d,3_2_d=@3_2_d,3_3_d=@3_3_d,3_4_d=@3_4_d,3_5_d=@3_5_d,3_6_d=@3_6_d,location=@location WHERE id=@id", MyConn2);
                    MyCommand2.Parameters.AddWithValue("@location", memory.sValue_location);
                    MyCommand2.Parameters.AddWithValue("@id", memory.sValue_id);
                    MyCommand2.Parameters.AddWithValue("@Tema1_1", theme.sValue_them1_1);
                    MyCommand2.Parameters.AddWithValue("@Tema1_2", theme.sValue_them1_2);
                    MyCommand2.Parameters.AddWithValue("@Tema1_3", theme.sValue_them1_3);
                    MyCommand2.Parameters.AddWithValue("@Tema1_4", theme.sValue_them1_4);
                    MyCommand2.Parameters.AddWithValue("@Tema1_5", theme.sValue_them1_5);
                    MyCommand2.Parameters.AddWithValue("@Tema1_6", theme.sValue_them1_6);
                    MyCommand2.Parameters.AddWithValue("@Tema1_7", theme.sValue_them1_7);
                    MyCommand2.Parameters.AddWithValue("@Tema1_8", theme.sValue_them1_8);
                    MyCommand2.Parameters.AddWithValue("@1_1_d", theme.sValue_1_1_d);
                    MyCommand2.Parameters.AddWithValue("@1_2_d", theme.sValue_1_2_d);
                    MyCommand2.Parameters.AddWithValue("@1_3_d", theme.sValue_1_3_d);
                    MyCommand2.Parameters.AddWithValue("@1_4_d", theme.sValue_1_4_d);
                    MyCommand2.Parameters.AddWithValue("@1_5_d", theme.sValue_1_5_d);
                    MyCommand2.Parameters.AddWithValue("@1_6_d", theme.sValue_1_6_d);
                    MyCommand2.Parameters.AddWithValue("@1_7_d", theme.sValue_1_7_d);
                    MyCommand2.Parameters.AddWithValue("@1_8_d", theme.sValue_1_8_d);
                    
                    MyCommand3.Parameters.AddWithValue("@location", memory.sValue_location);
                    MyCommand3.Parameters.AddWithValue("@id", memory.sValue_id);
                    MyCommand3.Parameters.AddWithValue("@Tema2_1", theme.sValue_them2_1);
                    MyCommand3.Parameters.AddWithValue("@Tema2_2", theme.sValue_them2_2);
                    MyCommand3.Parameters.AddWithValue("@Tema2_3", theme.sValue_them2_3);
                    MyCommand3.Parameters.AddWithValue("@Tema2_4", theme.sValue_them2_4);
                    MyCommand3.Parameters.AddWithValue("@Tema2_5", theme.sValue_them2_5);
                    MyCommand3.Parameters.AddWithValue("@2_1_d", theme.sValue_2_1_d);
                    MyCommand3.Parameters.AddWithValue("@2_2_d", theme.sValue_2_2_d);
                    MyCommand3.Parameters.AddWithValue("@2_3_d", theme.sValue_2_3_d);
                    MyCommand3.Parameters.AddWithValue("@2_4_d", theme.sValue_2_4_d);
                    MyCommand3.Parameters.AddWithValue("@2_5_d", theme.sValue_2_5_d);
 
                    MyCommand4.Parameters.AddWithValue("@location", memory.sValue_location);
                    MyCommand4.Parameters.AddWithValue("@id", memory.sValue_id);
                    MyCommand4.Parameters.AddWithValue("@Tema3_1", theme.sValue_them3_1);
                    MyCommand4.Parameters.AddWithValue("@Tema3_2", theme.sValue_them3_2);
                    MyCommand4.Parameters.AddWithValue("@Tema3_3", theme.sValue_them3_3);
                    MyCommand4.Parameters.AddWithValue("@Tema3_4", theme.sValue_them3_4);
                    MyCommand4.Parameters.AddWithValue("@Tema3_5", theme.sValue_them3_5);
                    MyCommand4.Parameters.AddWithValue("@Tema3_6", theme.sValue_them3_5);
                    MyCommand4.Parameters.AddWithValue("@3_1_d", theme.sValue_3_1_d);
                    MyCommand4.Parameters.AddWithValue("@3_2_d", theme.sValue_3_2_d);
                    MyCommand4.Parameters.AddWithValue("@3_3_d", theme.sValue_3_3_d);
                    MyCommand4.Parameters.AddWithValue("@3_4_d", theme.sValue_3_4_d);
                    MyCommand4.Parameters.AddWithValue("@3_5_d", theme.sValue_3_5_d);
                    MyCommand4.Parameters.AddWithValue("@3_6_d", theme.sValue_3_6_d);
 
                    MyConn2.Open();
                    save.Text = "Сохранения сессии. Подождите..";
                    MyCommand2.ExecuteNonQuery();   
                }
                save.Text = "Успешно !!! ";
                this.Close();
                Application.Exit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
06.10.2018, 20:49
Ответы с готовыми решениями:

Оптимизация последовательных запросов к БД
Всем привет! Пишу программку, которая из БД MSSQL2008 только читает данные, вывожу в датагридвью....

Оптимизация запросов SQL в C#
Всем привет. Коротко расскажу о задаче своей. Есть реально большая база данных(порядка миллиона...

Оптимизация запросов к OleDB
Нужно было реализовать update полей в базе при совпадении вводимых значений из textbox и insert,...

Оптимизация запросов
Где можно коротко и ясно прочитать про оптимизацию запросов и использование планов выполнения...

2
Эксперт .NET
6452 / 4053 / 1599
Регистрация: 09.05.2015
Сообщений: 9,487
06.10.2018, 20:57 2
Тут только если менять типы полей theme.sValue_them1_X, theme.sValue_1_X_d и т.д. на массивы/списки и циклом прогонять...
1
2 / 2 / 4
Регистрация: 26.09.2016
Сообщений: 108
06.10.2018, 21:18  [ТС] 3
максиму что у меня получилось
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
private void Teal_Click(object sender, EventArgs e)
        {
 
            try
            {
                string myConnection = System.Configuration.ConfigurationManager.ConnectionStrings["myDatabaseConnection"].ConnectionString;
                using (var MyConn2 = new MySqlConnection(myConnection))
                {
                    save.Text = "Сохранения сессии. Подождите";
                    var MyCommand2 = new MySqlCommand("UPDATE clients SET  Tema1_1=@Tema1_1, Tema1_2=@Tema1_2, Tema1_3=@Tema1_3, Tema1_4=@Tema1_4, Tema1_5=@Tema1_5, Tema1_6=@Tema1_6, Tema1_7=@Tema1_7, Tema1_8=@Tema1_8, 1_1_d=@1_1_d,1_2_d=@1_2_d,1_3_d=@1_3_d,1_4_d=@1_4_d,1_5_d=@1_5_d,1_6_d=@1_6_d,1_7_d=@1_7_d,1_8_d=@1_8_d,Tema2_1=@Tema2_1, Tema2_2=@Tema2_2, Tema2_3=@Tema2_3, Tema2_4=@Tema2_4, Tema2_5=@Tema2_5, 2_1_d=@2_1_d,2_2_d=@2_2_d,2_3_d=@2_3_d,2_4_d=@2_4_d,2_5_d=@2_5_d,Tema3_1=@Tema3_1, Tema3_2=@Tema3_2, Tema3_3=@Tema3_3, Tema3_4=@Tema3_4, Tema3_5=@Tema3_5,Tema3_6=@Tema3_6, 3_1_d=@3_1_d,3_2_d=@3_2_d,3_3_d=@3_3_d,3_4_d=@3_4_d,3_5_d=@3_5_d,3_6_d=@3_6_d,location=@location WHERE id=@id", MyConn2);
                    MyCommand2.Parameters.AddWithValue("@location", memory.sValue_location);
                    MyCommand2.Parameters.AddWithValue("@id", memory.sValue_id);
                    MyCommand2.Parameters.AddWithValue("@Tema1_1", theme.sValue_them1_1);
                    MyCommand2.Parameters.AddWithValue("@Tema1_2", theme.sValue_them1_2);
                    MyCommand2.Parameters.AddWithValue("@Tema1_3", theme.sValue_them1_3);
                    MyCommand2.Parameters.AddWithValue("@Tema1_4", theme.sValue_them1_4);
                    MyCommand2.Parameters.AddWithValue("@Tema1_5", theme.sValue_them1_5);
                    MyCommand2.Parameters.AddWithValue("@Tema1_6", theme.sValue_them1_6);
                    MyCommand2.Parameters.AddWithValue("@Tema1_7", theme.sValue_them1_7);
                    MyCommand2.Parameters.AddWithValue("@Tema1_8", theme.sValue_them1_8);
                    MyCommand2.Parameters.AddWithValue("@1_1_d", theme.sValue_1_1_d);
                    MyCommand2.Parameters.AddWithValue("@1_2_d", theme.sValue_1_2_d);
                    MyCommand2.Parameters.AddWithValue("@1_3_d", theme.sValue_1_3_d);
                    MyCommand2.Parameters.AddWithValue("@1_4_d", theme.sValue_1_4_d);
                    MyCommand2.Parameters.AddWithValue("@1_5_d", theme.sValue_1_5_d);
                    MyCommand2.Parameters.AddWithValue("@1_6_d", theme.sValue_1_6_d);
                    MyCommand2.Parameters.AddWithValue("@1_7_d", theme.sValue_1_7_d);
                    MyCommand2.Parameters.AddWithValue("@1_8_d", theme.sValue_1_8_d);
                    MyCommand2.Parameters.AddWithValue("@Tema2_1", theme.sValue_them2_1);
                    MyCommand2.Parameters.AddWithValue("@Tema2_2", theme.sValue_them2_2);
                    MyCommand2.Parameters.AddWithValue("@Tema2_3", theme.sValue_them2_3);
                    MyCommand2.Parameters.AddWithValue("@Tema2_4", theme.sValue_them2_4);
                    MyCommand2.Parameters.AddWithValue("@Tema2_5", theme.sValue_them2_5);
                    MyCommand2.Parameters.AddWithValue("@2_1_d", theme.sValue_2_1_d);
                    MyCommand2.Parameters.AddWithValue("@2_2_d", theme.sValue_2_2_d);
                    MyCommand2.Parameters.AddWithValue("@2_3_d", theme.sValue_2_3_d);
                    MyCommand2.Parameters.AddWithValue("@2_4_d", theme.sValue_2_4_d);
                    MyCommand2.Parameters.AddWithValue("@2_5_d", theme.sValue_2_5_d);
                    MyCommand2.Parameters.AddWithValue("@Tema3_1", theme.sValue_them3_1);
                    MyCommand2.Parameters.AddWithValue("@Tema3_2", theme.sValue_them3_2);
                    MyCommand2.Parameters.AddWithValue("@Tema3_3", theme.sValue_them3_3);
                    MyCommand2.Parameters.AddWithValue("@Tema3_4", theme.sValue_them3_4);
                    MyCommand2.Parameters.AddWithValue("@Tema3_5", theme.sValue_them3_5);
                    MyCommand2.Parameters.AddWithValue("@Tema3_6", theme.sValue_them3_5);
                    MyCommand2.Parameters.AddWithValue("@3_1_d", theme.sValue_3_1_d);
                    MyCommand2.Parameters.AddWithValue("@3_2_d", theme.sValue_3_2_d);
                    MyCommand2.Parameters.AddWithValue("@3_3_d", theme.sValue_3_3_d);
                    MyCommand2.Parameters.AddWithValue("@3_4_d", theme.sValue_3_4_d);
                    MyCommand2.Parameters.AddWithValue("@3_5_d", theme.sValue_3_5_d);
                    MyCommand2.Parameters.AddWithValue("@3_6_d", theme.sValue_3_6_d);
 
                    MyConn2.Open();
                    save.Text = "Сохранения сессии. Подождите..";
                    MyCommand2.ExecuteNonQuery();
                }
                save.Text = "Успешно !!! ";
                this.Close();
                Application.Exit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Добавлено через 1 минуту
но опять же строка "var MyCommand2 = new MySqlCommand("UPDA" слишком уж длинная
0
06.10.2018, 21:18
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
06.10.2018, 21:18
Помогаю со студенческими работами здесь

Оптимизация запросов
Здравствуйте. Стоит задача написать форум. Темы сортируются по дате. Увеличивается время выборки...

Оптимизация запросов
Всем добрый день ! Мне необходимо оптимизировать запросы ко многим таблицам, то есть структура моей...

Оптимизация запросов
Здравствуйте! Помоги те пожалуйста написать запросы...очень нужно...спасибо за ранее) Задача...

Оптимизация запросов
Всем привет! Очень долго сражаюсь с одним запросом и никак не могу победить. Кажется уже, что...

Оптимизация запросов
Как можно оптимизировать запрос, в котором используется оператор 'LIKE'?? Запрос: << select * from...

оптимизация sql запросов
интересно как вы оптимизируете sql запросы в ваших скриптах поделитесь идеями и опытом ?


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru