Ho un file di Excel e voglio aggiornare più righe in una sheet.So scrivo questo codice:eseguire il comando update multipla su Excel
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
{
}
e ho ottenuto questo errore:
Syntax error (missing operator) in query expression 'id = 1 update [Data14City$] set B_1_1 = 0 ,B_1_2 = 8 ,B_1_3 = 17 ,B_1_4 = 0 where id = 2'.
ed io quando aggiungo ;
a questa linea:
strUpd += "update [Data14City$] set B_1_1 = 5 ,B_1_2 = 26 ,B_1_3 = 44 ,B_1_4 = 8 where id = 1;";
ho ottenuto questo errore:
012.351.Characters found after end of SQL statement.
come posso eseguire più istruzioni in Excel?
grazie
sua mancante o "E"/"OR": - "update [Data14City $] set B_1_1 = 5, B_1_2 = 26, B_1_3 = 44, B_1_4 = 8 dove id = 1 OR set B_1_1 = 0 , B_1_2 = 8, B_1_3 = 17, B_1_4 = 0 dove id = 2 " – Derek
Spiega di più – Arian
Ami ha ragione nel dire che stai cercando di ottenere: - Tabella UPDATE SET A WHERE ID = 1 OR/E SET B WHERE ID = 2? Hai provato la stringa sopra? – Derek