我在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
答案 0 :(得分:0)
据我所知,你不需要按照你的要求去做。将SQLBaseConnection
投射到MySQLConnection
无济于事(据我所知,甚至无法实现)。您需要建立类型MySQLConnection
的新连接以连接到MySQL数据库,然后将该连接对象提供给Insert201
方法。如果您在建立第二个连接对象时需要任何帮助,请参阅this StackOverflow question and answer。