Postgres 更新导致 FillinValues 失败
我正在尝试通过 Postgres 函数对 WPF 应用程序进行更新,但引发了异常。 “填充值失败”.. 我真的不明白为什么..谢谢帮助.. 这是 C# 代码:
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 中。 感谢您的帮助!
I'm trying to do an update with an WPF application through a Postgres Function but an exception is raised..
"FillinValues failed"..
I don't really understand why.. Thnks for help..
Here is the C# Code:
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
}
}
}
Here's the Postgres function :
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
;
Here's the stacktrace of Exception:
à 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
Error seems to be in the oledbprovider..
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速谷歌搜索发现了一些 2006 年 EnterpriseDB 论坛的链接以及 此线程有关 PgOleDb 驱动程序 来自2011 年 1 月 2 日。您不使用托管 ADO.NET 提供程序是否有原因? Npgsql 是一个正在积极开发的 ADO.NET 提供程序。
Some quick googling turned up a few links to the EnterpriseDB forums from 2006 as well as this thread about the PgOleDb driver from January 2, 2011. Is there a reason you're not using a managed ADO.NET provider? Npgsql is an ADO.NET provider that is under active development.