Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this UPDATE table statement correct in an msdn topic

I have seen this type of UPDATE statement (just like insert statement) in the following msdn topic:

http://msdn.microsoft.com/en-us/library/aa0416cz.aspx#Y2461

UPDATE statement:-

adapter.UpdateCommand = New SqlCommand("UPDATE Customers " &
  "(CustomerID, CompanyName) VALUES(@CustomerID, @CompanyName) " & _
  "WHERE CustomerID = @oldCustomerID AND CompanyName = " &
  "@oldCompanyName", connection)

Is this statement correct or not?

I have tried executing it and it is giving syntax errors.

like image 838
teenup Avatar asked Dec 22 '22 17:12

teenup


1 Answers

No, it should be:

UPDATE Customers
SET 
CustomerID = @CustomerID,
CompanyName = @CompanyName
WHERE
CustomerID = @oldCustomerID AND
CompanyName = @oldCompanyName

Or to be complete with your sample code, it should be:

adapter.UpdateCommand = New SqlCommand("UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName WHERE CustomerID = @oldCustomerID AND CompanyName = @oldCompanyName", connection)

Here is another reference for you and this situation: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx

like image 93
Dan Waterbly Avatar answered Jan 07 '23 18:01

Dan Waterbly