Skip to Content
0
Jul 02, 2020 at 04:43 PM

VB.Net error - Unable to cast object of type 'System.Data.DataSet' to type 'System.Data.IDataReader'

560 Views Last edit Jul 03, 2020 at 12:12 AM 4 rev

Hi Experts,

I got the error:

Unable to cast object of type 'System.Data.DataSet' to type 'System.Data.IDataReader

after running an application to export data from mysql database table and to import the data in the hana schema table. Both tables have set to have same field codes and data types. Both tables have the same table name, i.e. Billing_Data. The schema name in hana is Staging_Db. The schema name in mysql is mysqlstg_db

My application is developed using vb.net 2010. The sap hana version is 1.0 for SAP Business One Hana. I did not use SAP B1H DI API.

#Region "Common Variable"
  Private ComDset As New DataSet
#End Region
#Region "daily work"

 Private Sub trfbilldata(ByVal DBSAddOn As String, ByVal TrfNum As String, ByRef sAccumErrMsg As String)
Dim...
Dim..

Me.Cursor = Cursors.WaitCursor
        myconn = New MySqlConnection
        myconn.ConnectionString = "server=" + sDBOrigin + ";" _
        & "user id=" + sDBUserName + ";" _
        & "password=" + sDBUserPassword + ";" _
        & "database=" + sDBName + ";"


  Try
            myconn.Open()
            SQL = "SELECT * FROM BILLING_DATA where " & _
                         " coalesce(RULE1,'')='' and coalesce(TrfNum ,'') = ''"

            myCommand.Connection = myconn
            myCommand.CommandText = SQL

            myAdapter.SelectCommand = myCommand
            myAdapter.Fill(myData)

            myconn.Close()


        Catch myerror As MySqlException
            MessageBox.Show("Error: " & myerror.Message)
        Finally
            myconn.Dispose()
        End Try

        Dim filename As String
        Dim col, row As Integer
        Dim adp2 As New MySqlDataAdapter(SQL, myconn)
        Try
            ComDset.Reset()
            adp2.Fill(ComDset, "TTbl")
            If ComDset.Tables.Count < 0 Or ComDset.Tables(0).Rows.Count <= 0 Then
                '  Exit Sub
                'End If
                ' Catch ex As Exception
                MsgBox("Data Kosong")
                Exit Sub
            Else
                '### start ###'
                Dim SQLconn As New HanaConnection
                Dim sConn As String = ""
                sConn = "Server=" + HanaSName +
                                        ";UserID=" + HanaDbUserName +
                                        ";Password=" + HanaDbPassword +
                                        "; Current Schema =" + HanaDbName

                SQLconn.ConnectionString = sConn
                SQLconn.Open()

                Using Bulkcopy As HanaBulkCopy = New HanaBulkCopy(SQLconn)
                    Bulkcopy.DestinationTableName = "BILLING_DATA"
                    Bulkcopy.WriteToServer(ComDset)
                End Using
                SQLconn.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            '## END ##'
        End Try

I use hanabulkcopy because I remember sap run simpler. So, my application is expected to run simpler.

But this time seems not. Pls kindly share the solution for the problem. Thanks in advance.


Rgds,

Steve