2013-07-05 97 views
1

我試圖使用連接的ado.net層對winform執行更新操作。更新數據與連接的ado.net層

這裏使用此查詢我得到異常的代碼

   string insertCmdStr = "UPDATE ARTICLE(SecondId,Group,Code,Name) WHERE ([email protected])"; 
       insertCmdStr += "VALUES(@Idd,@group,@code,@name)"; 
       FbCommand cmd = new FbCommand(insertCmdStr, fbConn, tran); 
       cmd.Parameters.AddWithValue("@P1", id); 
       cmd.Parameters.AddWithValue("@Idd", idd); 
       cmd.Parameters.AddWithValue("@group", group); 
       cmd.Parameters.AddWithValue("@code", code); 
       cmd.Parameters.AddWithValue("@name", name);  
       cmd.ExecuteNonQuery(); 

  • $ {例外「動態SQL錯誤\ r \ nSQL錯誤代碼= -104 \ r \ nToken未知 - 行1,列15 \ r \ n(「} System.Exception {FirebirdSql.Data.FirebirdClient.FbException}

回答

1

不應該查詢是這樣的:

UPDATE ARTICLE 
SET 
    SecondId = @Idd, 
    Group = @group, 
    Code = @code, 
    Name = @name 
WHERE ID = @P1 
2

UPDATE語句通常構成如下:

UPDATE TABLE 
SET Field1 = Value 
, Field2 = Value 
, Field3 = Value 
WHERE ID = Value 

因此,您可以:

string insertCmdStr = "UPDATE ARTICLE SET SecondId = @Idd, Group = @group, code = @code, name = @name WHERE [email protected];" 

我也建議改變insertCmdStrupdateCmdStr只是爲了澄清你想達到的目標。