Update OLEDB Not working

1

Good afternoon, I'm trying to update an excel worksheet but the command is not changing any values, it's just corrupting the worksheet.

I create the last two columns and rewrite the other

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();
}
    
asked by anonymous 02.02.2018 / 18:12

2 answers

3

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

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

You can try changing the order in the syntax:

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

o

="Update" + [@lStrNome_Table_Planilha] + " set MODO = 1 where id = 1"
    
05.02.2018 / 17:56