0

我在 SQLBase 中选择了一些值,我想将它们导入 MySQL。但问题仍然存在,如我的标题所示。

场景是这样的:我只需要在 SQLBase 中选择一些字段及其值,然后将它们插入 MySQL。如何将sqlbase数据导入mysql?

这是我的代码:

       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

然后在另一个子过程中我称之为:

    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
4

1 回答 1

0

据我从您的问题中可以看出,您不需要按照您的要求进行操作。铸造SQLBaseConnectionaMySQLConnection无济于事(据我所知,甚至不可能)。您需要建立一个新的连接类型MySQLConnection来连接到您的 MySQL 数据库,然后将该连接对象提供给您的Insert201方法。如果您在建立第二个连接对象时需要任何帮助,请参阅此 StackOverflow 问题和答案

于 2013-05-23T02:24:17.890 回答