Parameter name not found
必须是数据库驱动程序中的错误。如果没有
完整异常跟踪
,但我猜测DevArt必须要求您在尝试设置参数之前设置SQL文本。
例如
Command = new Devart.Data.PostgreSql.PgSqlCommand();
Command.CommandText = "SELECT ...."; /* or whatever your SQL is */
Command.Parameters.AddWithValue("@TestName", testmaster.TestName);
Command.Parameters.AddWithValue("@TestShortName", testmaster.TestShortName);
(我没用过,我只是路过
the examples in some of the docs
,虽然它们指的是Oracle参数,但对于基础知识来说似乎是一样的。)
然而,DevArt也可能无法解析
DO
块和
$$
引用。要确认这一点,请尝试:
Command = new Devart.Data.PostgreSql.PgSqlCommand();
Command.Parameters.AddWithValue("@TestName", testmaster.TestName);
Command.Parameters.AddWithValue("@TestShortName", testmaster.TestShortName);
Command.CommandText = "Insert into \"TestMaster\"(\"TestName\", \"TestShortName\", \"RCUID\", \"RCDate\", \"RCTime\") values (:TestName, :TestShortName, 0, CURRENT_DATE, CURRENT_TIME(0)) RETURNING \"TestID\" INTO newTestID;";
如果此操作有效
做
块没有,那么可能是因为DevArt无法解析
做
块或其
$$
引用以查找参数。
您可能需要改用SQL函数(假设您在第一条语句之后尝试执行更多操作,否则使用
做
完全阻塞)。然后在单独的语句中调用该函数。例如,首先在没有任何参数的情况下执行该SQL:
CREATE OR REPLACE FUNCTION myfunc(testname text, testshortname text) returns void AS $$
DECLARE
newTestID INT;
BEGIN
INSERT into "TestMaster"("TestName", "TestShortName", "RCUID", "RCDate", "RCTime")
VALUES (testname, testshortname, 0, CURRENT_DATE, CURRENT_TIME(0))
RETURNING TestID INTO newTestID;
-- whatever you want to do with newTestID here
END$$;
然后
运行另一条语句来调用函数,例如:
Command = new Devart.Data.PostgreSql.PgSqlCommand();
Command.CommandText = "SELECT myfunc(:TestName, :TestShortName)";
Command.Parameters.AddWithValue("@TestName", testmaster.TestName);
Command.Parameters.AddWithValue("@TestShortName", testmaster.TestShortName);
称之为。
没有
CREATE TEMPORARY FUNCTION
所以你必须
DROP FUNCTION
如果你不想保留和重复使用它,那就在以后。