Good day,

Just want to ask some help, Please!

I always encounter "Cannot find Table 0" when i call Stored Procedure in DB2 using VB .Net with Ole DBConnection Provider. Here is my code:

  Private Sub cmdPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPost.Click

        rsSearch = clsDAOMngr.getConfigParam(2)

        For i = 0 To rsSearch.Tables.Count Step 1

        With rsSearch.Tables(0)
        MsgBox(.Rows(i)(0).ToString())
        End With

        Next

    End Sub

    '-------------------------------------------------------

      Public Function getConfigParam(ByVal strParameter As String) As DataSet
        getConfigParam = Nothing
        Dim sProcedure As String = ""

        sProcedure = "EDMS.SAMPLE_SELECT2"

        getConfigParam = clsDBMngr.executeStoredProcedure_split(sProcedure, strParameter, 1)

    End Function

    '-------------------------------------------------------

    Public Function executeStoredProcedure_split(ByVal spname As String, ByVal strparam As String, ByVal numberOfSInput As Integer) As DataSet
        executeStoredProcedure_split = Nothing

            Try
            command.CommandType = CommandType.StoredProcedure
            command.CommandText = spname
            command.Connection = connection_oledb
            connection_oledb.Open()

                arrStrParam = strparam.Split("|")
            OleDbCommandBuilder.DeriveParameters(command)

            For i = 0 To numberOfSInput - 1 Step 1
                parameterValue = arrStrParam(i)
                command.Parameters(i).Value = parameterValue
            Next

            adapter = New OleDbDataAdapter(command)
            executeStoredProcedure_split = New DataSet(command.CommandText)
            Dim dataTable As DataTable = executeStoredProcedure_split.Tables(0)
            adapter.Fill(executeStoredProcedure_split)

            command.Parameters.Clear()
            connection_oledb.Close()
            Return executeStoredProcedure_split
            Catch
            connection_oledb.Close()
                MsgBox(Err.Description, MsgBoxStyle.Critical, strtitle)
                Exit Function
            End Try

    End Function

Please help.
Thanks in advance :))

I see a couple of problems that may occur.

First, you need to change this code:

 For i = 0 To rsSearch.Tables.Count Step 1

To this:

 For i = 0 To rsSearch.Tables.Count - 1 Step 1

To safeguard from index out of range.

Second, do you know that the stored procedure is actually returning a value?

Have you fired the store procedure in DB2 to see the data?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.