Topic
  • 1 reply
  • Latest Post - ‏2012-09-17T17:55:54Z by Arvind_Gupta
SystemAdmin
SystemAdmin
2826 Posts

Pinned topic Best way to get a dataset

‏2012-09-17T12:20:01Z |
I need to do this with a proc passing 2 vars. I am using IBM.Data.DB2
Any code anywhere? Have not worked with DB2 in a while are there Data Access Application Blocks for .NET anymore. My version is 9.5 I think
Updated on 2012-09-17T17:55:54Z at 2012-09-17T17:55:54Z by Arvind_Gupta
  • Arvind_Gupta
    Arvind_Gupta
    58 Posts

    Re: Best way to get a dataset

    ‏2012-09-17T17:55:54Z  
    Hi,

    Please refer below example and confirm if this helps you?

    Procedure
    =========
    CREATE PROCEDURE PROCEDURE1 (IN EMPLOYEENO VARCHAR(128), IN FIRSTNAME VARCHAR(128))
    DYNAMIC RESULT SETS 1
    P1: BEGIN
    DECLARE cursor1 CURSOR WITH RETURN for
    SELECT * FROM EMPLOYEE WHERE EMPNO = EMPLOYEENO and FIRSTNME= FIRSTNAME;
    OPEN cursor1;
    END P1
    DB2 .Net code
    =============
    DB2Connection Conn= new DB2Connection("Server=localhost:50000;User ID=db2admin;Password=*****;Database=SAMPLE");
    Conn.Open();
    DB2Command cmd = Conn.CreateCommand();
    String procCall = "CALL PROCEDURE1(?,?)";
    cmd.CommandText = procCall;

    DB2Parameter param1 = new DB2Parameter("@param1", DB2Type.Char);
    param1.Direction = ParameterDirection.Input;
    param1.Value = "000010";

    cmd.Parameters.Add(param1);
    DB2Parameter param2 = new DB2Parameter("@param2", DB2Type.Char);
    param2.Direction = ParameterDirection.Input;
    param2.Value = "CHRISTINE";
    cmd.Parameters.Add(param2);

    DB2DataAdapter adapter = new DB2DataAdapter(cmd);
    DataSet ds = new DataSet();
    adapter.Fill(ds, "Employee");

    Thanks,
    Arvind