从.NET C#调用参数化iSeries存储过程

时间:2015-03-06 05:22:57

标签: c# stored-procedures odbc ibm-midrange db2-400

我在AS400上创建了一个存储过程,它接收2个参数,如果找到则返回000,如果找不到则返回001。我认为我没有CommandText的正确语法。以下将0和00传递给AS400。当我在准备好的陈述中观看CommandText时,它仍会显示??。不确定它是否正常填满。

我可以硬编码参数“CALL DKDEXE.DKSLICCHK1('AAAAAA1',' 43个空格')”并且AS400获取正确的数据并返回有效的001但我无法获得该001回到我的计划。我没有关于如何调用存储过程并获取返回代码的想法。我的代码出了什么问题?

using (OdbcConnection cn = new OdbcConnection("Driver=Client Access ODBC Driver (32-bit);System=X;Uid=U;Pwd=P"))
{
    cn.Open();

    using (OdbcCommand cm = cn.CreateCommand())
    { 
        cm.CommandText = "CALL DKDEXE.DKSLICCHK1 ('?','?')";
        cm.CommandType = CommandType.StoredProcedure;

        cm.Parameters.Add("P1", OdbcType.Char).Value = "AAAAAAA1";
        cm.Parameters["P1"].Size = 8;
        cm.Parameters["P1"].Direction = ParameterDirection.Input;

        cm.Parameters.Add("P2", OdbcType.Char);
        cm.Parameters["P2"].Size = 43;
        cm.Parameters["P2"].Direction = ParameterDirection.InputOutput;

        cm.Prepare();
        cm.ExecuteNonQuery();

        string result = cm.Parameters["P2"].Value.ToString();
    }
}

AS400上的代码

    PROCEDURE DIVISION USING CALL-PARMS
                     CALL-PARMS1

    1000-MAIN.

        PERFORM 9999-PGM-INZ
        PERFORM 9999-PGM-EXIT

        GOBACK

        CONTINUE.

    9999-PGM-INZ.

        SET GOOD-RTN-CD TO TRUE
        MOVE SPACES TO RTN-MSG-1

        CALL 'SETLIB' USING
           OBJ-LIB
           DB-LIB
        END-CALL

        DISPLAY  CODE
        DISPLAY  NUMBER
        SET PGM-STR-PRG-MSG TO TRUE
        PERFORM 9999-SND-PRG-MSG
        CONTINUE.

    9999-SND-ON-OFF-MSG.
          EVALUATE TRUE
             WHEN CHK
                SET CHK1   TO TRUE
          END-EVALUATE
          EVALUATE TRUE
             WHEN GOOD-RTN-CD
                SET GOOD-RTN-TXT TO TRUE
             WHEN OTHER
                SET BAD-RTN-TXT TO TRUE
          END-EVALUATE
       STRING
           NUMBER        OF CALL-PARMS
           LS-RTN-CD
           RTN-MSG-1
           REQ-TYP-TXT
           REQ-RESULT-TXT
             DELIMITED BY SIZE
                INTO SND-ERR-MSG-SUB-DTA
        END-STRING
        PERFORM 9999-SND-ERR-MSG
        CONTINUE.
   9999-SND-PRG-MSG.
       SET LOG-MSG TO TRUE
       SET LOG-IN-PRG-MSG-ID TO TRUE
          STRING
             THIS-PROGRAM-NAME
             CUR-PRG-MSG
             DELIMITED BY SIZE
                INTO SND-ERR-MSG-SUB-DTA
          END-STRING
          PERFORM 9999-SND-ERR-MSG
       CONTINUE.


    9999-PGM-EXIT.
        PERFORM 9999-SND-ON-OFF-MSG
        SET PGM-END-PRG-MSG TO TRUE
        PERFORM 9999-SND-PRG-MSG
        CONTINUE.

0 个答案:

没有答案