Search code examples
mysqlvb.netsqlbase

How to cast object of type 'gupta.sqlbase.data.sqlbaseconnection' to type 'mysql.data.mysqlclient.mysqlconnection'


I selected some values in SQLBase and I want to import them in MySQL. But the problem persists as indicated in my title.

The scenario is this: I have to select only some fields and their values in SQLBase and insert them in MySQL. How do i import sqlbase data to mysql?

Here is my code:

       Dim conn As New SQLBaseConnection("DB=Source;SERVER=SERVER1;UID=SYSADM;PWD=password;INI=C:\Program Files\Gupta\SQLBase901\sql.ini")
    Try
        conn.Open()
        Dim adaptor As New SQLBaseDataAdapter
        Dim ds As New DataSet
        adaptor.SelectCommand() = New SQLBaseCommand("SELECT * FROM PERSON WHERE TYPE='E'", conn)
        ds = New DataSet()
        adaptor.Fill(ds, "ID")
        Dim datTable As DataTable = ds.Tables("ID")

        Dim id, type, name, proximity, department, section, costCenter, lastName, firstName, midName, company As String

        If datTable.Rows.Count > 0 Then

            For i As Integer = 0 To datTable.Rows.Count - 1

                id = datTable.Rows(i)(0)
                type = datTable.Rows(i)(1)
                name = datTable.Rows(i)(8)
                proximity = datTable.Rows(i)(33)
                department = datTable.Rows(i)(51)
                section = datTable.Rows(i)(58)
                costCenter = datTable.Rows(i)(55)
                firstName = datTable.Rows(i)(3)
                midName = datTable.Rows(i)(4)
                lastName = datTable.Rows(i)(5)
                company = datTable.Rows(i)(50)

                Insert201(id, type, name, proximity, department, section, costCenter, lastName, firstName, midName, company, conn)
                i += 1
                Application.DoEvents()

            Next

        End If
        conn.Close()
    Catch ex As Exception
        'TextBox1.Text = ex.Message
    End Try

Then on another sub proc i call this:

    Public Sub Insert201(ByVal id, ByVal type, ByVal name, ByVal proximity, ByVal department, ByVal section, ByVal costCenter, ByVal lastName, ByVal firstName, ByVal midName, ByVal company, ByVal conn)

    Dim Query As String

    Query = "INSERT INTO tbl_201 VALUES ('" + id + "','" + type + "','" + name + "','" + proximity + "','" + department + "', '" + section + "', '" + costCenter + "','" + lastName + "', '" + firstName + "', '" + midName + "','" + company + "')"

    Try
        conn.Open()
        Dim sql As MySqlCommand = New MySqlCommand(Query, conn)
        sql.ExecuteNonQuery()
        'MsgBox("Record is Successfully Inserted")
        conn.Close()
    Catch ex As Exception
        conn.Close()
        MsgBox("Record is not Inserted" + ex.Message)
    End Try

End Sub

Solution

  • As far as I can see from your question you don't need to do as you've asked. Casting the SQLBaseConnection to a MySQLConnection won't help (and as far as I'm aware isn't even possible). You need to establish a new connection of type MySQLConnection to connect to your MySQL database and then provide that connection object to your Insert201 method. If you need any help establishing the second connection object, please consult this StackOverflow question and answer.