create a faster insert statement MySQL

How can I make this query faster

   query = "INSERT INTO ControllerMemoryLogData (UploadTime,EraseID,Technician,Location,ControllerSerialNumber,ToolNumber,SurveyTime,PulseSyncTime,Angle,Azimuth,DipAngle,HoursLeft,Voltage,BatteryUsed,Temperature, ";
            query += " TGF,TMF,NumberOfPulses,Frame0,Frame1,Frame2,Frame3,Frame4,Frame5,Frame6,Frame7,Frame8,Frame9,Frame10,PulseEnergy0,PulseEnergy1,PulseEnergy2,PulseEnergy3, ";
            query += " PulseEnergy4,PulseEnergy5,PulseEnergy6,PulseEnergy7,PulseEnergy8,PulseEnergy9,PulseEnergy10,PulseEnergy11,PulseEnergy12,PulsePing0,PulsePing1,PulsePing2, ";
            query += " PulsePing3,PulsePing4,PulsePing5,PulsePing6,PulsePing7,PulsePing8,PulsePing9,PulsePing10,PulsePing11,PulsePing12,PulseJam0,PulseJam1,PulseJam2,PulseJam3, ";
            query += " PulseJam4,PulseJam5,PulseJam6,PulseJam7,PulseJam8,PulseJam9,PulseJam10,PulseJam11,PulseJam12,DefaultLocationIndex) ";
            query += " VALUES (@UploadTime, @EraseID,@Technician,@Location,@ControllerSerialNumber,@ToolNumber,@SurveyTime,@PulseSyncTime,@Angle,@Azimuth,@DipAngle,@HoursLeft,@Voltage,@BattUsed,@Temperature,";
            query += " @TGF,@TMF,@NumberOfPulses,@Frame0,@Frame1,@Frame2,@Frame3,@Frame4,@Frame5,@Frame6,@Frame7,@Frame8,@Frame9,@Frame10,@PulseEnergy0,@PulseEnergy1,@PulseEnergy2,@PulseEnergy3, ";
            query += " @PulseEnergy4,@PulseEnergy5,@PulseEnergy6,@PulseEnergy7,@PulseEnergy8,@PulseEnergy9,@PulseEnergy10,@PulseEnergy11,@PulseEnergy12,@PulsePing0,@PulsePing1,@PulsePing2, ";
            query += " @PulsePing3,@PulsePing4,@PulsePing5,@PulsePing6,@PulsePing7,@PulsePing8,@PulsePing9,@PulsePing10,@PulsePing11,@PulsePing12,@PulseJam0,@PulseJam1,@PulseJam2,@PulseJam3, ";
            query += " @PulseJam4,@PulseJam5,@PulseJam6,@PulseJam7,@PulseJam8,@PulseJam9,@PulseJam10,@PulseJam11,@PulseJam12,@DefaultLocationIndex); ";
            using (MySqlConnection cn = new MySqlConnection(globalconnStr))
            using (MySqlCommand cmd = new MySqlCommand(query, cn))
            {
                try
                {
                    cn.Open();
                    cmd.Parameters.AddWithValue("@UploadTime", DateTime.Now);
                    cmd.Parameters.AddWithValue("@EraseID", controllermemorylog.EraseID);
                    cmd.Parameters.AddWithValue("@Technician", controllermemorylog.technician.Replace("'", "`"));
                    cmd.Parameters.AddWithValue("@Location", controllermemorylog.location.Replace("'", "`"));
                    cmd.Parameters.AddWithValue("@ControllerSerialNumber", controllermemorylog.controllerserialnumber);
                    cmd.Parameters.AddWithValue("@ToolNumber", controllermemorylog.toolnumber);
                    cmd.Parameters.AddWithValue("@SurveyTime", controllermemorylog.SurveyTime.ToString("yyyyMMddHHmmss"));
                    cmd.Parameters.AddWithValue("@PulseSyncTime", controllermemorylog.PulseSyncTime.ToString("yyyyMMddHHmmss"));
                    cmd.Parameters.AddWithValue("@Angle", controllermemorylog.angle.ToString("G"));
                    if (controllermemorylog.azimuth.ToString("G") != "NaN")
                    {
                        cmd.Parameters.AddWithValue("@Azimuth", controllermemorylog.azimuth.ToString("G"));
                    }
                    else
                    {
                        string nullstring = string.Empty;
                        cmd.Parameters.AddWithValue("@Azimuth", null);
                    }
                    if (controllermemorylog.dip.ToString("G") != "NaN")
                    {
                        cmd.Parameters.AddWithValue("@DipAngle", controllermemorylog.dip.ToString("G"));
                    }
                    else
                    {
                        string nullstring = string.Empty;
                        cmd.Parameters.AddWithValue("@DipAngle", null);
                    }
                    cmd.Parameters.AddWithValue("@HoursLeft", controllermemorylog.hoursleft.ToString("G"));
                    cmd.Parameters.AddWithValue("@Voltage", controllermemorylog.voltage.ToString("G"));
                    cmd.Parameters.AddWithValue("@BattUsed", controllermemorylog.battused.ToString("G"));
                    cmd.Parameters.AddWithValue("@Temperature", controllermemorylog.temperature.ToString("G"));
                    cmd.Parameters.AddWithValue("@TGF", controllermemorylog.tgf.ToString("G"));
                    if (controllermemorylog.voltage.ToString("G") != "NaN")
                    {
                        cmd.Parameters.AddWithValue("@TMF", controllermemorylog.voltage.ToString("G"));
                    }
                    else
                    {
                        string nullstring = string.Empty;
                        cmd.Parameters.AddWithValue("@TMF", null);
                    }
                    cmd.Parameters.AddWithValue("@NumberOfPulses", controllermemorylog.numberofpulses.ToString());
                    cmd.Parameters.AddWithValue("@Frame0", controllermemorylog.frame[0].ToString());
                    cmd.Parameters.AddWithValue("@Frame1", controllermemorylog.frame[1].ToString());
                    cmd.Parameters.AddWithValue("@Frame2", controllermemorylog.frame[2].ToString());
                    cmd.Parameters.AddWithValue("@Frame3", controllermemorylog.frame[3].ToString());
                    cmd.Parameters.AddWithValue("@Frame4", controllermemorylog.frame[4].ToString());
                    cmd.Parameters.AddWithValue("@Frame5", controllermemorylog.frame[5].ToString());
                    cmd.Parameters.AddWithValue("@Frame6", controllermemorylog.frame[6].ToString());
                    cmd.Parameters.AddWithValue("@Frame7", controllermemorylog.frame[7].ToString());
                    cmd.Parameters.AddWithValue("@Frame8", controllermemorylog.frame[8].ToString());
                    cmd.Parameters.AddWithValue("@Frame9", controllermemorylog.frame[9].ToString());
                    cmd.Parameters.AddWithValue("@Frame10", controllermemorylog.frame[10].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy0", controllermemorylog.PulseEnergy[0].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy1", controllermemorylog.PulseEnergy[1].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy2", controllermemorylog.PulseEnergy[2].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy3", controllermemorylog.PulseEnergy[3].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy4", controllermemorylog.PulseEnergy[4].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy5", controllermemorylog.PulseEnergy[5].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy6", controllermemorylog.PulseEnergy[6].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy7", controllermemorylog.PulseEnergy[7].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy8", controllermemorylog.PulseEnergy[8].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy9", controllermemorylog.PulseEnergy[9].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy10", controllermemorylog.PulseEnergy[10].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy11", controllermemorylog.PulseEnergy[11].ToString());
                    cmd.Parameters.AddWithValue("@PulseEnergy12", controllermemorylog.PulseEnergy[12].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing0", controllermemorylog.PulsePing[0].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing1", controllermemorylog.PulsePing[1].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing2", controllermemorylog.PulsePing[2].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing3", controllermemorylog.PulsePing[3].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing4", controllermemorylog.PulsePing[4].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing5", controllermemorylog.PulsePing[5].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing6", controllermemorylog.PulsePing[6].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing7", controllermemorylog.PulsePing[7].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing8", controllermemorylog.PulsePing[8].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing9", controllermemorylog.PulsePing[9].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing10", controllermemorylog.PulsePing[10].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing11", controllermemorylog.PulsePing[11].ToString());
                    cmd.Parameters.AddWithValue("@PulsePing12", controllermemorylog.PulsePing[12].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam0", controllermemorylog.PulseJam[0].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam1", controllermemorylog.PulseJam[1].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam2", controllermemorylog.PulseJam[2].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam3", controllermemorylog.PulseJam[3].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam4", controllermemorylog.PulseJam[4].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam5", controllermemorylog.PulseJam[5].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam6", controllermemorylog.PulseJam[6].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam7", controllermemorylog.PulseJam[7].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam8", controllermemorylog.PulseJam[8].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam9", controllermemorylog.PulseJam[9].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam10", controllermemorylog.PulseJam[10].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam11", controllermemorylog.PulseJam[11].ToString());
                    cmd.Parameters.AddWithValue("@PulseJam12", controllermemorylog.PulseJam[12].ToString());
                    cmd.Parameters.AddWithValue("@DefaultLocationIndex", controllermemorylog.defaultLocationIndex);

                    try
                    {
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                    }
                    catch (MySqlException ex)
                    {
                        SaveSQLCommands(cmd.CommandText);
                    }

Open in new window

LVL 6
r3nderAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
Instead of keep using query += to create a dynamic piece of SQL you could have all that as a stored procedure and use that instead.

It might run a millisecond or two faster (which is what you specifically ask for) - but an INSERT command is going to take time.

(check if your end table you insert to has indexes, if it has indexes then any that are superfluous will slow things down a lot.)
0
 
r3nderAuthor Commented:
I just have an ID field that is a primary key and auto increment - but no indexes
0
 
r3nderAuthor Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.