execute multiple update command on Excel

不打扰是莪最后的温柔 提交于 2019-12-05 07:03:16

You don't really need to stack up your updates like that (in fact, as has been pointed out above, you can't). It doesn't take much longer to execute them individually. Here's the code I've been using and it works fine (I actually have mine in a loop, but it'll work equally well if you can't loop your updates).

cn.Open();

using (OleDbCommand cmd = cn.CreateCommand())
{
    cmd.CommandText = "update [Data14City$] set  B_1_1 = 5 ,B_1_2 = 26 ,B_1_3 = 44 ,B_1_4 = 8  where id = 1";
    cmd.ExecuteNonQuery();
    cmd.CommandText = "update [Data14City$] set  B_1_1 = 0 ,B_1_2 = 8 ,B_1_3 = 17 ,B_1_4 = 0  where id = 2";
    cmd.ExecuteNonQuery();

    // ... and so on
}

cn.Close();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!