Topic
No replies
KristinSmith
KristinSmith
1 Post
ACCEPTED ANSWER

Pinned topic Problems Referencing Column Names with .NET DB2ConnectDataAdapter

‏2013-12-05T17:56:53Z |

When we are calling a stored procedure that returns a cursor, we have been unable to reference columns in the result set by their name despite providing column names in the stored procedure.  The name of the columns coming back from the data table is "Column1", etc.  We are successfully able to access data by using the index of the column, but this is not ideal in case we change the order of the return columns.

Is this some known bug or is there some mainframe setting where we need to instruct the stored proc to send back column names with a cursor?

 

 

Here is a sample of what we are doing:

Mainframe native stored procedure:
===========================================================================
DECLARE OUT_RSLT_SET_CURSOR CURSOR WITH RETURN FOR
    SELECT PART_NBR          AS PART_NBR                        ßWant to reference this name below
                  ,QTY                        AS QTY                         ßWant to reference this name below                  
      FROM SESSION.RSLTTBL                          
      WITH UR;                                      
 
 
 
Logic in .NET:
==========================================================================
 
        Dim DatTbl As New DataTable
        Dim partQty As New Part

        Dim connection As New DB2Connection(DB2_CNXN)
 
        Try
            connection.Open()
 
            Dim command As DB2Command = connection.CreateCommand()
            command.CommandType = CommandType.Text
            command.CommandText = STORED_PROC
 
             ……………………………………………..
 
            Dim adapter As New DB2DataAdapter
            adapter.SelectCommand = command
            adapter.Fill(DatTbl)
 
 
        For Each row As DataRow In DatTbl.Rows
 
            Dim partQty As New Part
            partQty.PartNbr = CStr(row(0))  àwe get an undefined reference if we try to put "PART_NBR" here
            partQty.Qty = CLng(row(1))
 
        Next

 

 

Updated on 2013-12-05T19:19:57Z at 2013-12-05T19:19:57Z by KristinSmith