我有一个Excel文件,我想更新一个sheet.So多行我写这篇文章的代码:
OleDbConnection cn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + serverPath + ";Extended Properties = Excel 8.0;");
try
{
strUpd = "";
strUpd += "update [Data14City$] set B_1_1 = 5 ,B_1_2 = 26 ,B_1_3 = 44 ,B_1_4 = 8 where id = 1 ";
strUpd += " update [Data14City$] set B_1_1 = 0 ,B_1_2 = 8 ,B_1_3 = 17 ,B_1_4 = 0 where id = 2";
cn.Open();
OleDbCommand cmdInsert = new OleDbCommand(strUpd, cn);
cmdInsert.ExecuteNonQuery();
cn.Close();
}
catch
{
}
我得到这个错误:
语法错误(缺少操作者)在查询表达式ID = 1个更新[Data14City $]设置B_1_1 = 0,B_1_2 = 8,B_1_3 = 17,B_1_4 = 0其中id = 2“。
我当我添加;
这条线:
strUpd += "update [Data14City$] set B_1_1 = 5 ,B_1_2 = 26 ,B_1_3 = 44 ,B_1_4 = 8 where id = 1;";
我得到这个错误:
SQL语句的结束后找到的字符。
我怎么可以在Excel中执行多个语句?
谢谢