2011-04-24 45 views
0

我試圖通過Postgres函數做WPF應用程序的更新,但引發異常。 「FillinValues失敗」.. 我真的不明白爲什麼.. Thnks for幫助.. 下面是C#代碼:FillinValues失敗,Postgres更新

public static int UpdateCategorie(int aID_CAT, string aINTITULE_CAT, string aDESCRIPTION_CAT, int? aPID_CAT) 
    { 
     using (OleDbConnection connex = new OleDbConnection(ConfigurationManager.ConnectionStrings["BMGDB"].ToString())) 
     { 
      OleDbCommand command = new OleDbCommand("UpdateCategorie", connex);     
      command.Parameters.Add("IDCategorie", OleDbType.VarChar).Value = aID_CAT; 
      command.Parameters.Add("Intitule", OleDbType.VarChar).Value = aINTITULE_CAT; 
      command.Parameters.Add("Description", OleDbType.VarChar).Value = aDESCRIPTION_CAT; 
      //command.Parameters.Add("PID", OleDbType.Integer).Value = aPID_CAT; 

      if (aPID_CAT == null) 
      { 
       command.Parameters.Add("PID", OleDbType.Integer).Value = null; 
      } 
      else 
      { 
       command.Parameters.Add("PID", OleDbType.Integer).Value = (int)aPID_CAT; 
      } 

      connex.Open(); 
      int rows = command.ExecuteNonQuery(); //permet de retourner un entier indiquant le nbr de row affectées 
      connex.Close(); 
      if (rows == 1) 
      { 
       return 1; // TODO - ShowDialog 
      } 
      else 
      { 
       return -1;// TODO - ShowDialog 
      } 
     } 
    } 

這裏的Postgres的功能:

CREATE OR REPLACE FUNCTION UpdateCategorie(IDcategorie INTEGER, Intitule TEXT, Description TEXT, PID INTEGER) RETURNS VOID 
AS $$ 
    BEGIN 
    INSERT INTO CATEGORIE_HIST (ID_CAT, Intitule_CAT, Description_CAT, Modification_CAT, PID_CAT) 
    SELECT c.ID_CAT, c.Intitule_CAT, c.Description_CAT, c.Modification_CAT, PID_CAT 
    FROM CATEGORIE c 
    WHERE c.ID_CAT = $1 
    ; 
    UPDATE CATEGORIE 
    SET Intitule_CAT = $2, 
     Description_CAT = $3, 
     PID_CAT = $4, 
     Modification_CAT = CURRENT_TIMESTAMP 
    WHERE ID_CAT = $1; 
    END; 
    $$ 
LANGUAGE plpgsql 
; 

這裏是異常的堆棧跟蹤:

à System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 
    à System.Data.OleDb.OleDbCommand.ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, Object& executeResult) 
    à System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 
    à System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) 
    à System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) 
    à System.Data.OleDb.OleDbCommand.ExecuteNonQuery() 
    à BMG.DAL.Data_Provider.UpdateCategorie(Int32 aID_CAT, String aINTITULE_CAT, String aDESCRIPTION_CAT, Nullable`1 aPID_CAT) dans Projects\BMG\Code c#\BMG.BackOffice\BMG.DAL\Classes\Data_Provider.cs:ligne 399 
    à BMG.BLL.Classes.CATEGORIE_MANAGER.Update(Int32 aID_CAT, String aINTITULE_CAT, String aDESCRIPTION_CAT, Nullable1 aPID_CAT) dansProjects\BMG\Code \BMG.BLL\Classes\CATEGORIE_MANAGER.cs:ligne 128 

錯誤似乎是在oledbprovider .. 感謝您的幫助!

+0

* FillinValues失敗*不是Postgres錯誤消息。您需要提供錯誤出現在代碼中的確切位置*(例如打印堆棧跟蹤)和完整的Postgres錯誤消息。 – 2011-04-24 13:28:50

+0

Tks for propositions,@mu太短,我沒有改變,沒有更好的,@a_horse_with_no_name,我編輯了我的問題。 – bAN 2011-04-25 07:37:32

回答

1

從2011年1月2日起,一些快速的谷歌搜索出現了幾條2006年EnterpriseDB論壇以及this thread about the PgOleDb driver的鏈接。是不是有沒有使用託管ADO.NET提供程序的原因? Npgsql是一個正在積極開發中的ADO.NET提供程序。

+0

thks,它與Npgsql一起工作,它沒有任何理由使用PgOleDb,更容易,因爲他默認存在..非常感謝.. – bAN 2011-04-27 09:30:06