adapter.update函数非常缓慢

时间:2019-07-08 04:12:47

标签: c# mysql

我正在尝试从C#应用程序向MySQL表插入大量数据。 我不知道为什么要花14分钟才能插入6500行数据, 每行有4列。

起初,我使用的是简单的“插入”命令,但该命令无效, 我读到adapter.Update方法更好,我现在尝试了,但是还是 不够快...

    //Create new dataset
    DataSet DataTariff = new DataSet("DataTariff");
                DataTariff.Tables.Add();
                for (int i = 0; i < ClientInfoTabels.Tables[n].Rows.Count; i++)
                {


                    DataTable FirstCycle = new DataTable();
                    MySqlDataAdapter DataTariffAdapter = new MySqlDataAdapter("select* from customers.`" + ClientsIDList[n].ToString() + "_" + (i + 1).ToString() + "` ORDER BY Date DESC LIMIT 1;", ConnectionString);
                    MySqlCommandBuilder DataTariffCmb = new MySqlCommandBuilder(DataTariffAdapter);

//Get table format from MySQL table

                    DataTariffAdapter.Fill(FirstCycle);

                    DataTable TempTable = new DataTable();
                    TempTable = DataCalc.Tables[ClientInfoTabels.Tables[n].Rows[i][4].ToString()];

                    DataTariffAdapter = new MySqlDataAdapter("select* from customers.`" + ClientsIDList[n].ToString() + "_" + (i + 1).ToString() + "` ORDER BY Date DESC LIMIT 0;", ConnectionString);
                    DataTariffCmb = new MySqlCommandBuilder(DataTariffAdapter);
                    DataTariff.Tables.Add(ClientsIDList[n].ToString() + "_" + (i + 1).ToString());
                    DataTariffAdapter.Fill(DataTariff.Tables[ClientsIDList[n].ToString() + "_" + (i + 1).ToString()]);
                    DataTariff.Tables[i + 1].ImportRow(FirstCycle.Rows[0]);

//Do calculations , Import the data to the TempTable - This takes few seconds 

                    foreach (DataRow dr in TempTable.Rows)
                    {
                        acr.ImportRow(DataTariff.Tables[i + 1], DataTariff.Tables[i + 1].Rows[DataTariff.Tables[i + 1].Rows.Count - 1]);
                        acr.SortByTariff(dr, DataTariff.Tables[i + 1], ElecTariff, i + 1, ClientInfoTabels.Tables[n]);

                    }

                    DataTariff.Tables[ClientsIDList[n].ToString() + "_" + (i + 1).ToString()].Rows.RemoveAt(0);

//Insert new data back to MySQL table - THIS TAKES 14 MINUTES per 6.5K rows!!

                  DataTariffAdapter.Update(DataTariff.Tables[ClientsIDList[n].ToString() + "_" + (i + 1).ToString()]);

                }

我原本希望在几分钟后插入6.5K行,也许不是 我很现实,但我希望有人能帮助我更快地完成工作。

0 个答案:

没有答案