wolfsor wrote:
Can this command update the database and work?
Nope, it'll fail. You're concatenating a comma just before terminating the Sql statement. Take a look at the last piece of the code;
+ DATENAME (YEAR, OrderDate)," + ";";
That would result in this;
+ DATENAME (YEAR, OrderDate),;
Remove that last comma, and it would work.
Some additional remarks, as you asked how to 'correct' the statement;
- A SqlCommand implements the IDisposable interface. You'd best encapsulate it in a
using
directive. - The
SqlConnection
class has a factory-method called "CreateCommand" that you can use to create a new command for that particular connection - You're concatenating too much, at the expense of readability. Example;
+' ' + 'of' + ' '
would be more readable in this form;
+' of '