SQL Update Statement in c# with reserved-words

0

I have a problem with update statement:

In column names i have characters like: % , []. In "insert into" statement I just put that in quotation marks and worked. But can't execute this update statement:

UPDATE WIG_BANKI 
SET "Nazwa_spolki" = @BankNames, 
"Pakiet" = @Packet, 
"Udzial_w_portfelu[%]" = @ShareInPortfolio, 
"Udzial_w_obrocie[%]" = @ShareOfTurnover, 
"Wplyw_na_zmiane_indeksu[%]" = @ImpactOnChangeOfIndex, 
"Zmiana_kursu_spolki[%]" = @ExchangeRate, 
"Kurs[PLN]" = @PLN_ExchangeRate 
 WHERE "Nazwa_spolki" != @BankNames, 
       "Pakiet" != @Packet, 
       "Udzial_w_portfelu[%]" != @ShareInPortfolio, 
       "Udzial_w_obrocie[%]" != @ShareOfTurnover, 
       "Wplyw_na_zmiane_indeksu[%]" != @ImpactOnChangeOfIndex, 
       "Zmiana_kursu_spolki[%]" != @ExchangeRate, 
       "Kurs[PLN]" != @PLN_ExchangeRate

Then I execute the whole statement like this:

command.Parameters[Globals.columnsNamesArrayDB[i]].Value = array[i].ToString(); // here in for loop I set what is @BankNames etc.
command.CommandText = sbAllDataUpdate.ToString();
command.ExecuteNonQuery();

then this message error shows

System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near ','.

I have no idea how to correct it

c#
sql
sql-update
reserved-words
asked on Stack Overflow Jul 18, 2018 by janek9971 • edited Jul 18, 2018 by Juan Carlos Oropeza

1 Answer

3

For WHERE you separate conditions with logical operators AND OR

 WHERE "Nazwa_spolki" != @BankNames AND
       "Pakiet" != @Packet AND
       "Udzial_w_portfelu[%]" != @ShareInPortfolio AND
       "Udzial_w_obrocie[%]" != @ShareOfTurnover AND
       "Wplyw_na_zmiane_indeksu[%]" != @ImpactOnChangeOfIndex AND 
       "Zmiana_kursu_spolki[%]" != @ExchangeRate AND 
       "Kurs[PLN]" != @PLN_ExchangeRate
answered on Stack Overflow Jul 18, 2018 by Juan Carlos Oropeza

User contributions licensed under CC BY-SA 3.0