Oracle输出参数返回null

时间:2014-11-24 21:09:09

标签: c# sql oracle-sqldeveloper

我正在尝试从数据库中获取输出值。 Ween我在数据库端调试它似乎正在打印正确的值。但是当我从C#侧获取相同的数据时,我得到空值。

CREATE OR REPLACE PROCEDURE GetAssetInfoSelect
(inTransactionID in varchar2,
varProcessorAction out varchar2,
varTransactionStatus out varchar2)
is

begin
 if (inTransactionID is not null) then
  select ProcessorAction, TransactionStatus into varProcessorAction, varTransactionStatus
    from tblAssetIDTransactions
    where TransactionID = inTransactionID;

end if;

END GetAssetInfoSelect;

enter image description here

private static bool GetAssetInfoSelect(string strTransactionID)
{
        try
        {
            OracleConnection conn = new OracleConnection(connstring);
            OracleCommand cmd = new OracleCommand();

            cmd.Connection = conn;
            conn.Open();
            cmd.CommandText = "GetAssetInfoSelect";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new OracleParameter("inTransactionID", OracleType.Char)).Value = strTransactionID;
            cmd.Parameters.Add(new OracleParameter("varProcessorAction", OracleType.Char,200)).Direction = ParameterDirection.Output;
            cmd.Parameters.Add(new OracleParameter("varTransactionStatus", OracleType.Char,200)).Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();

            Debug.WriteLine(cmd.Parameters["varProcessorAction"].Value);
            Debug.WriteLine(cmd.Parameters["varTransactionStatus"].Value);
            //immitate if (inTransactionID is not null AND varProcessorAction = 'A' AND varTransactionStatus = 'A') then
            if (!string.IsNullOrEmpty(strTransactionID) && cmd.Parameters["varProcessorAction"].Equals('A') && cmd.Parameters["varTransactionStatus"].Equals('A'))
            {
                conn.Close();
                return true;
            }
            else
            {
                conn.Close();
                return false;
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

Debug.WriteLine输出null

我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试在conn.Close();完成后关闭您的连接Debug.WriteLine