MySqlConnection conn = new MySqlConnection(connectStr);
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
const string insertHeader="INSERT INTO `local_data`(`point_id`,`path_name`,`point_value`,`store_time`) VALUES";
for (int i = 0; i < points.Count; i++)
{
if (i%50 == 0)
{
cmd.CommandText=insertHeader;
}
if (cmd.CommandText !=insertHeader)
{
cmd.CommandText +=",";
}
cmd.CommandText += string.Format("({0},"{1}",{2},"{3}")",
points[i].Point_ID,
points[i].Path_Name,
points[i].Point_Value,
points[i].Store_Time);
if((i > 0 && i % 50==0)||i== points.Count-1)
{
sqlList.Add(cmd.CommandText);
cmd.ExecuteNonQuery();
}
}
cmd.Dispose();
conn.Close();