0

我有更新数据库表的方法,但是当我调用它时,我有一个异常“'('附近的语法不正确。”

这是方法

 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;
     }

这是数据库表列

客户表

4

6 回答 6

5

您的语法错误不正确。请参阅更新查询语法的链接

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
于 2013-09-26T05:23:57.183 回答
5

你的sql update说法是错误的。有关更新语句的更多信息,请参见

     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";
于 2013-09-26T05:24:21.000 回答
2

请参阅更新语句语法:

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

您不能批量更新表中的值

于 2013-09-26T05:25:18.620 回答
2

UPDATE语法错误。。

尝试

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"
于 2013-09-26T05:27:39.673 回答
1

从未见过这样的更新声明-通常是set followingid = @followingid, fullname = @fullname等等

于 2013-09-26T05:25:07.110 回答
0

有语法错误,更新语句是这样使用的

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
于 2013-09-26T06:30:54.140 回答