简体   繁体   中英

SQL UPDATE Command

Question. I'm trying to use SQL to update a listview in C#. Using the Query Builder I can do a select, update, insert and delete. Ive got my select but I'm trying to get my update to work with no luck.( I want to use the update button on the listview to update the record) I need some insight as I think I'm writing it wrong. Thanks

 UPDATE       SF1411
 SET  ( ItemNumber, QuoteNumber, Item, Descp, Route, Unit, QTYOH, EXTQTY, CSTCD, 
      PCOST, SCOST, ACOST, TCOST, ICOST, Date, BIZCODE, DeleteItem)   
  =  SELECT [ItemNumber], [QuoteNumber], [Item], [Descp], [Route], [Unit], [QTYOH], 
     [EXTQTY], [CSTCD], [PCOST], [SCOST], [ACSOT], [TCOST], [ICOST], [Date], [BIZCODE],   
    [DeleteItem] 
    FROM [SF1411] WHERE ([QuoteNumber] = @QuoteNumber)

Im sorry if I understand you wrong, but shouldn't an update statement look like this..

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

If I am correct your update command is wrong.

you need to tell value of each column rather than just fire a select command.

Just set individual values like below:

UPDATE SF1411
SET ItemNumber = SELECT [ItemNumber] FROM [SF1411] WHERE ([QuoteNumber] = @QuoteNumber);

Mostly this is used to update a specific value or if using select in set then it used to select from different table like:

Update table set column= "value" where condition;

or:

Update table set column = select column from tbl where condition;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM