以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- MYSQL读取的数据如何复制到另外一张表 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=150735) |
-- 作者:BG小白 -- 发布时间:2020/6/5 23:49:00 -- MYSQL读取的数据如何复制到另外一张表 Dim conn As MySql.Data.MySqlClient.MySqlConnection Dim cmd As MySql.Data.MySqlClient.MySqlCommand Dim connStr As String = "server=****; port=****; user id=****; password=****; database=****;CharSet=utf8" \'设置你的数据库连接字符串 conn = New MySql.Data.MySqlClient.MySqlConnection(connStr) conn.Open Dim mda As New MySql.Data.MySqlClient.MySQLDataAdapter("select * fro m ipos_sptpk" , conn) \'这里可以设置你的查询语句 Dim ds As New System.Data.DataSet() mda.Fill(ds, "TableTemp") \'MySQLDataAdapter方法把数据放到一个新建的临时表里,这个临时表名可自定义,我这里写TableTemp Dim Vals As List(of String()) Vals = ds.DataTables("TableTemp").GetValues("spdm|pic_name") For i As Integer = 0 To Vals.Count - 1 Dim dr As DataRow = DataTables("SPTPB").AddNew() dr("pic_name") = Vals(i)(1) Next conn.close [此贴子已经被作者于2020/6/5 23:51:28编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/6/6 9:03:00 -- foxtable的datatable是自己封装的,才有GetValues这种方法,.net的datatable是没有的。只能是逐行遍历取值 Dim mda As New MySql.Data.MySqlClient.MySQLDataAdapter("select distinct spdm,pic_name from ipos_sptpk" , conn) \'这里可以设置你的查询语句 Dim ds As New System.Data.DataSet() mda.Fill(ds, "TableTemp") \'MySQLDataAdapter方法把数据放到一个新建的临时表里,这个临时表名可自定义,我这里写TableTemp For Each r As System.Data.DataRow In ds.Tables(0).Rows Dim dr As DataRow = DataTables("SPTPB").AddNew() dr("spdm") = r("spdm") |