我在postgres中有一个函数返回两个参数,我在我的应用程序中使用C#来获取out参数的值。但是当我尝试执行代码时,这个错误显示。我不明白我做了什么我正在附上c#代码和postgres函数。谢谢。 这是postgres函数:
CREATE OR REPLACE FUNCTION sylvia2.pro_att_login_simple_create(
p_userid text,
p_originalsn text,
p_sendersn text,
p_remark text,
p_accessmethod text,
p_photopath text,
OUT p_outputmessage text,
OUT p_logindatetime timestamp with time zone)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
declare
p_count numeric;
p_log_in_out text;
begin
set search_path to sylvia2;
select count(userid) into p_count from attendance where userid = p_userid
and (to_date (to_char (timestamp_server, 'mm/dd/yyyy hh:mi:ss am'), 'mm/dd/yyyy hh:mi:ss am' ))::date = current_date;
if(p_count = 0) then select 'in' into p_log_in_out ;
else select 'out' into p_log_in_out ;
end if;
insert into attendance (userid, timestamp, timestamp_server, timestamp_actatek, eventtrigger, originalsn,
sendersn, remark, accessmethod, photopath
)
values (p_userid, current_date, current_date, current_date, p_log_in_out, p_originalsn,
p_sendersn, p_remark, p_accessmethod, p_photopath
);
p_outputmessage := p_log_in_out;
select current_date into p_logindatetime;
end;
$BODY$;
ALTER FUNCTION sylvia2.pro_att_login_simple_create(text, text, text, text, text, text)
OWNER TO postgres;
这是C#代码:
NpgsqlCommand cmd = new NpgsqlCommand();
cmd.CommandText = "sylvia2.PRO_ATT_LOGIN_SIMPLE_CREATE";
cmd.CommandType = CommandType.StoredProcedure;
foreach (empAttendanceDS.EmpAttendance_NoCalculationRow row in attDS.EmpAttendance_NoCalculation.Rows)
{
if (clientName == "Uddipan")
{
#region For Uddipan
cmd.Parameters.Add("p_UserID", row.LoginID);
cmd.Parameters.Add("p_OriginalSN", message);
cmd.Parameters.Add("p_SenderSN", message);
if (!row.IsRemarkNull()) cmd.Parameters.Add("p_Remark", row.Remark);
else cmd.Parameters.Add("p_Remark", remarks);
cmd.Parameters.Add("p_AccessMethod", message);
cmd.Parameters.Add("p_PhotoPath", message);
cmd.Parameters.Add("p_OutputMessage", NpgsqlTypes.NpgsqlDbType.Varchar, 1000).Direction = ParameterDirection.Output;
cmd.Parameters.Add("p_LoginDateTime", NpgsqlTypes.NpgsqlDbType.Date, 1000).Direction = ParameterDirection.Output;
bError = false;
nRowAffected = -1;
nRowAffected = ADOController.Instance.ExecuteNonQuery(cmd, connDS.DBConnections[0].ConnectionID, ref bError);
if (bError == true)
{
ErrorDS.Error err = errDS.Errors.NewError();
err.ErrorCode = ErrorCode.ERR_DB_OPERATION_FAILED.ToString();
err.ErrorTier = ErrorTier.ERR_TIER_DL.ToString();
err.ErrorLevel = ErrorLevel.ERR_LEVEL_SEVER.ToString();
err.ErrorInfo1 = ActionID.ACTION_ADD_ATTENDANCE_SIMPLE_LOGIN.ToString();
errDS.Errors.AddError(err);
errDS.AcceptChanges();
}
successMsg = cmd.Parameters["p_OutputMessage"].Value.ToString();
loginDateTime = cmd.Parameters["p_LoginDateTime"].Value.ToString();
stringDS.DataStrings.AddDataString(successMsg);
stringDS.DataStrings.AddDataString(loginDateTime);
stringDS.AcceptChanges();