以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- mysql怎么批量添加数据 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=111143) |
||||
-- 作者:jinzhengbe -- 发布时间:2017/12/15 20:00:00 -- mysql怎么批量添加数据 不知道是不是因为代码太长的原因, 提示参数错误,没有办法提交 所以将代码写到 文本文件里了,请各位帮忙看看
非常感谢 此主题相关图片如下:qq截图20171215204414.png
[此贴子已经被作者于2017/12/15 20:05:44编辑过]
|
||||
-- 作者:jinzhengbe -- 发布时间:2017/12/15 20:01:00 -- 11 |
||||
-- 作者:有点蓝 -- 发布时间:2017/12/15 21:18:00 -- Dim Cols1() As String = {"cn_name1","costPrice","weight","length","eng_name","pic","cn_name","width","gongxiang","isCheck","mu","lei","cs2","cs1","cs3","adddata"} For Each dr1 As DataRow In DataTables("商品").Select("[id] >0") Dim dr6 As DataRow = DataTables("ivan").AddNew() For i As Integer = 0 To Cols1.Length -1 dr6(Cols1(i)) = dr1(Cols1(i)) Next Next
|
||||
-- 作者:jinzhengbe -- 发布时间:2017/12/16 0:07:00 -- 不是这个啊,cl6时原先就有的。时mssq 我时想实现上面的同时 把数据也添加到mysql库的product表数据表中 Dim Cols1() As String = {"cn_name1","costPrice","weight","length","eng_name","pic","cn_name","width","gongxiang","isCheck","mu","lei","cs2","cs1","cs3","adddata"} For Each dr1 As DataRow In DataTables("商品").Select("[id] >0") Dim dr6 As DataRow = DataTables("ivan").AddNew() Dim dr7 As DataRow = DataTables("product").AddNew() For i As Integer = 0 To Cols1.Length -1 dr6(Cols1(i)) = dr1(Cols1(i)) \'想这个我知道 dr7(Cols1(i)) = dr1(Cols1(i)) \' 红色的部分是我想实现的功能 因为数据库是mysql 所以好像不能 向 dr6 一样使用(因为不能导入外部表) dr1 (sqlserver库) dr6 (sqlserver库) dr7 (mysql库) 从dr1 复制到dr6 我已经能做到了 但是从 dr1 复制到dr7 不明白应该怎么做,因为是不同的数据库 Next Next |
||||
-- 作者:有点蓝 -- 发布时间:2017/12/16 9:30:00 -- mysql表作为数据源给窗口后,就按照平时的用法一样使用窗口表即可,可以往窗口表里添加数据 保存数据到mysql表,可以取窗口表的basetable,使用MySQLDataAdapter的update功能 或者使用sql进行保存,看这里用法:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=105771
|
||||
-- 作者:jinzhengbe -- 发布时间:2017/12/17 15:09:00 -- 版主大师,你发的链接我已经看过了。我的mysql链接就是按照他的哪个做的。 但是他那里说的是 只能操作单行数据,不能操作多行啊。 MySQLDataAdapte而且有关这个的属性,帮助文档里也没有把? 我需要的就是能实现下面的功能/ 把 sqlserver里的数据批量添加到mysql表。 (假设mysql接受的数据表 为 aaa)能帮我实现一下么? 非常感谢
[此贴子已经被作者于2017/12/17 15:13:49编辑过]
|
||||
-- 作者:有点甜 -- 发布时间:2017/12/17 19:19:00 -- 1、看看
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=98689
2、mysql的表,直接显示到foxtable里面,如 Tables("窗口1_Table1").DataSource = mssql的表格
然后,在窗口表里面新增、修改等等操作,最后保存,参考1的方式。 |
||||
-- 作者:lexianfeng -- 发布时间:2017/12/19 15:52:00 -- \'\'\'打开mysql数据链接 Dim conn As MySql.Data.MySqlClient.MySqlConnection Dim cmd As MySql.Data.MySqlClient.MySqlCommand Dim connStr As String = "server=localhost; port=3307; user id=root; password=root; database=bb2_dt;CharSet=utf8" conn = New MySql.Data.MySqlClient.MySqlConnection(connStr) conn.Open Dim st1 As Date = Date.Now Dim strlist As List(Of String) \'\'\'合成变更数据语句 strlist = Functions.Execute("sql提取函数",Tables("A11"),"wtu","_Identify","wtu","wtu|kg|lbs","wtu|kg|lbs",2) \'\'\'更新mysql中的数据 For Each s As String In strlist cmd = new MySql.Data.MySqlClient.MySqlCommand(s, conn) \'更改col1=5 的行记录,col2的值为fox cmd.ExecuteNonQuery() \'执行sql数据操作 \'MessageBox.show(s) Next conn.close MessageBox.show("成功") \'\'\'Functions.Execute("sql提取函数",Tables("A11"),"wtu","_Identify","wtu","wtu|kg|lbs","wtu|kg|lbs",2) Dim tb As Table = Args(0) \'要提取的表格 Dim kName As String = Args(1) \'后台表格的名称 Dim tbid As String = Args(2) \'表格中的主键字段名 Dim kid As String = Args(3) \'后台表格的主键字段名 Dim bgzd As String = Args(4) \'表格中的字段,用|分割 Dim kbgzd As String = Args(5) \'对应的后台表中的字段,用|分割 Dim lx As Integer = Args(6) \'数据源的类型,Access=1,sql=2 \'************ 生成字段对应表 ***************************************************************** Dim bgzds() As String = bgzd.Split("|") Dim kbgzds() As String = kbgzd.Split("|") If bgzds.Length <> kbgzds.Length Then Return Nothing \'长度不等,说明设置错误,退出 Dim _表格_字段对应表 As New Dictionary(Of String, String) \'新建一个用于存放字段对应的字典 For Index As Integer = 0 To bgzds.Length - 1 _表格_字段对应表.Add(bgzds(Index),kbgzds(Index)) Next \'******************** 生成字段类型表 *************************************************** Dim _表格_字段类型表 As New Dictionary(Of String, String) \'新建一个用于存放字段类型 \'*************遍历获取列的类型 Dim s1 As String For Each s As String In _表格_字段对应表.Keys s1 = "未知" With tb.DataTable.DataCols(s) If .IsString Then s1 = "文本" If .IsNumeric Then s1 = "数值" If .IsDate Then s1 = "日期" If .IsBoolean Then s1 = "逻辑" End With _表格_字段类型表.Add(s, s1) Next \' \'获取主键列的类型 \' If tbid = "_Identify" Then s1 = "_Identify" Else With tb.DataTable.DataCols(tbid) s1 = "未知" If .IsString Then s1 = "文本" If .IsNumeric Then s1 = "数值" If .IsDate Then s1 = "日期" End With End If _表格_字段类型表.Add(tbid, s1) Dim strlist As New List(Of String) \'定义一个集合,用于返回 \' \'获取对象 \' Dim systable As System.Data.DataTable = tb.DataTable.BaseTable \' Dim sql As String Dim str As String Dim ChangeTable As System.Data.DataTable = systable.GetChanges(System.Data.DataRowState.Added) \'获取新增记录 If ChangeTable IsNot Nothing Then \'如果有新增记录 \' \'循环获取新增语句 Dim sql11 As String = "INSERT INTO " & kName & " (" \'生成语句前导 For Each str1 As String In _表格_字段对应表.Values sql11 += str1 & "," Next sql11 = sql11.Trim(",") & ") VALUES (" For Each dr As System.Data.DataRow In ChangeTable.Rows \'遍历设置列值 sql = sql11 For Each str1 As String In _表格_字段对应表.Keys str = "\'" & dr(str1) & "\'," Select Case _表格_字段类型表(str1) Case "数值" str = dr(str1) & "," Case "逻辑" If dr(str1) Then str = "1," Else str = "0," End If Case "日期" If lx = 1 Then \'Access str = "#" & dr(str1) & "#," End If End Select If str.Trim(","," ").Trim = "" OrElse str.Trim(",","#"," ") = "" OrElse str.Trim(",","\'"," ")= "" Then sql += "null," Else sql += str End If Next sql = sql.Trim(",") & ")" strlist.Add(sql) Next End If Dim strkey As String |
||||
-- 作者:lexianfeng -- 发布时间:2017/12/19 15:54:00 -- 以上可以实现从狐表中的表更新更改数据到 Mysql中的数据表
[此贴子已经被作者于2017/12/19 15:56:45编辑过]
|
||||
-- 作者:tennis -- 发布时间:2017/12/19 17:07:00 -- 建议狐表能对MYSQL数据源多多支援,毕竟市场上很多用户,好用又免费!! |