0

I have the method that do update to data base table but when I invoke it I have an exception "Incorrect syntax near '('."

Here is the method

 internal Boolean update(int customerID,int followingID, string fullName, string idNumber, string address, string tel, string mobile1, string mobile2, string email, string customerComment, DateTime timeStamp)
     {
         string sqlStatment = "update customers set (followingID, fullName,idNumber,address,tel,mobile1,mobile2,email,customerComment,timeStamp) = (@followingID, @fullName,@idNumber,@address,@tel,@mobile1,@mobile2,@email,@customerComment,@timeStamp) where customerID=@customerID";

         SqlConnection con = new SqlConnection();
         con.ConnectionString = connection;
         SqlCommand cmd = new SqlCommand(sqlStatment, con);

         cmd.Parameters.AddWithValue("@customerID", customerID);
         cmd.Parameters.AddWithValue("@followingID", followingID);
         cmd.Parameters.AddWithValue("@fullName", fullName);
         cmd.Parameters.AddWithValue("@idNumber", idNumber);
         cmd.Parameters.AddWithValue("@address", address);
         cmd.Parameters.AddWithValue("@tel", tel);
         cmd.Parameters.AddWithValue("@mobile1", mobile1);
         cmd.Parameters.AddWithValue("@mobile2", mobile2);
         cmd.Parameters.AddWithValue("@email", email);
         cmd.Parameters.AddWithValue("@customerComment", customerComment);
         cmd.Parameters.AddWithValue("@timeStamp", timeStamp);


         bool success = false;
         try
         {

             con.Open();
             cmd.ExecuteNonQuery();
             success = true;

         }
         catch (Exception ex)
         {

             success = false;
             //throw ex;
         }
         finally
         {
             con.Close();
         }
         return success;
     }

and here is the database table columns

Customers table

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Fadi Khalil
  • 291
  • 4
  • 8
  • 18

6 Answers6

5

Your Syntax error is incorrect.Please refer the link for Update Query Syntax

update customers 
set 
followingID= @followingID, 
fullName=@fullName,
idNumber=@idNumber,
address=@address,
tel=@tel,
mobile1=@mobile1,
mobile2=@mobile2,
email=@email,
customerComment=@customerComment,
timeStamp=@timeStamp
where customerID=@customerID
Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71
5

Your sql update statement is wrong. For more about update statement see

     string sqlStatment = "update customers set followingID=@followingID,
          fullName=@fullName,idNumber=@idNumber,address=@address,tel=@tel,
          mobile1=@mobile1,mobile2=@mobile2,email=@email,
          customerComment=@customerComment,timeStamp=@timeStamp
        where customerID=@customerID";
Amit
  • 15,217
  • 8
  • 46
  • 68
2

Please see the Update statement syntax:

http://www.w3schools.com/sql/sql_update.asp

you cannot bulk update values in the table

Manikandan Sigamani
  • 1,964
  • 1
  • 15
  • 28
2

UPDATE syntax is wrong..

Try

string sqlStatment = "UPDATE customers SET followingID= @followingID, fullName=@fullName, idNumber=@idNumber,address=@address,tel=@tel,mobile1=@mobile1,mobile2=@mobile2,email=@email,customerComment=@customerComment,timeStamp=@timeStamp WHERE customerID=@customerID"
Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
1

Never seen an update statement like that - normally it'd be set followingid = @followingid, fullname = @fullname etc, etc

Satpal
  • 132,252
  • 13
  • 159
  • 168
Andrew
  • 2,315
  • 3
  • 27
  • 42
0

There is syntax error, update statement is used like this

update customers set followingID=@followingID,
fullName=@fullName,
idNumber=@idNumber,
address=@address,
tel=@tel,
mobile1=@mobile1,
mobile2=@mobile2,
email=@email,
customerComment=@customerComment,
timeStamp=@timeStamp
where customerID=@customerID
Nitu Bansal
  • 3,826
  • 3
  • 18
  • 24