分组批量插入数据算法

database

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();

  

以上是 分组批量插入数据算法 的全部内容, 来源链接: utcz.com/z/531440.html

回到顶部