【发布时间】:2017-07-14 11:24:27
【问题描述】:
我需要从 sql 数据库中获取数据并以编程方式将其发送到 mysql 数据库我该怎么做?
这是我目前正在尝试的
Try
con3.ConnectionString = MyConnectionString
con3.Open()
Dim cmd As New MySqlCommand _
("SELECT kjuy6_postmeta.meta_value, kjuy6_posts.ID, kjuy6_posts.post_status, kjuy6_woocommerce_order_items.order_item_name FROM kjuy6_postmeta INNER JOIN kjuy6_posts ON kjuy6_postmeta.post_id = kjuy6_posts.ID And kjuy6_postmeta.post_id = kjuy6_posts.ID, kjuy6_woocommerce_order_items WHERE kjuy6_posts.post_type = 'shop_order' AND kjuy6_postmeta.meta_key = '_paid_date' OR kjuy6_postmeta.meta_key = '_billing_phone'")
cmd.Connection = con3
'Dim reader As MySqlDataReader = cmd.ExecuteReader
Dim da As New MySqlDataAdapter(cmd)
da.Fill(ds)
Dim a = ds.Tables(0).Rows(0).Item("meta_value")
Dim b = ds.Tables(0).Rows(0).Item("meta_value")
Dim c = ds.Tables(0).Rows(0).Item("post_status")
Dim d = ds.Tables(0).Rows(0).Item("order_item_name")
If Not IsNothing(cmd) Then
con.Open()
ExecuteData("INSERT INTO BillingInfo (vchUsername, vchExpiryDate, vchOrderStatus, vchSubscriptionType, intSubscriberid) VALUES('" & a & "','" & b & "','" & c & "','" & d & "', '" & SubscriberId & "')")
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
con3.Close()
con.Close()
End Try
以下是分离元值,并使用插入查询中的变量作为值
Dim da As New MySqlDataAdapter(cmd)
da.Fill(ds)
Dim a = ds.Tables(0).Rows(0).Item("meta_value")
Dim b = ds.Tables(0).Rows(0).Item("meta_value")
Dim c = ds.Tables(0).Rows(0).Item("post_status")
Dim d = ds.Tables(0).Rows(0).Item("order_item_name")
问题在于将正确的元值分配给变量,以便可以将其插入正确的列中
【问题讨论】:
-
如果您只是直接处理数据而不使用数据适配器,它可能会帮助您了解正在发生的事情的细节。如果您对使用数据适配器以外的其他东西感兴趣,请告诉我。我将作为答案发布。
-
感谢所有帮助,我认为提取所有信息并将它们插入正确列的唯一方法是进行子查询。
标签: mysql database wordpress vb.net select-query