Update OLEDB Not working

Asked

Viewed 131 times

0

Good afternoon, I am trying to update an excel spreadsheet but the command is not changing any value, it is only corrupting the spreadsheet.

I create the last two columns and rewrite the rest

connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + saveLocation + "; Extended Properties='Excel 12.0;HDR=YES'";
connection.Open();
        string sSql = "Create Table [" + lStrNome_Table_Planilha + "] (PROCESSO Int, ANO Int, MÊS Int, ID Int, VERBA Int, QTDE Int, VALOR Int, LOTE Int, MODO Int, VEZES Int)";
using (OleDbCommand oCmd = new OleDbCommand(sSql, connection))
{
    oCmd.ExecuteNonQuery();
}
sSql = "Update [" + lStrNome_Table_Planilha + "] set MODO = 1";
        using (OleDbCommand oCmd = new OleDbCommand(sSql, connection))
{
    oCmd.ExecuteNonQuery();
}
  • need to update all rows of the columns MODE and TIMES

2 answers

6

You can try to change the order in the syntax:

="Update" + @[lStrNome_Table_Planilha] + " set MODO = 1 where id = 1"

the

="Update" + [@lStrNome_Table_Planilha] + " set MODO = 1 where id = 1"

3


Hello, I got the solution, the problem was in the [] inside the field I was updating that I did not have. It was like this:

sSql = "Update [" + lStrNome_Table_Planilha + "] SET [MODO] = 1";
using (OleDbCommand oCmd = new OleDbCommand(sSql, connection))
{
   oCmd.ExecuteNonQuery();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.