以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- [求助]高速合并 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=115069)
|
-- 作者:15820092320
-- 发布时间:2018/2/28 15:45:00
-- [求助]高速合并
高速合并时,选择更新同主键记录无效,请问是怎么 回事?
我是想将这两个表添加合并为一个新表,并根据主键更新行列内容。
附测试表。
|
-- 作者:有点甜
-- 发布时间:2018/2/28 16:05:00
--
参考代码
Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then Dim t As Table = Tables("abc") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("企业名称 = \'" & sheet(n, 0).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim cname As String = sheet(0, i).text If cname > "" AndAlso t.Cols.Contains(cname) Then r(cname) = sheet(n, i).Text End If Next Next t.ResumeRedraw() End If
|
-- 作者:15820092320
-- 发布时间:2018/2/28 16:48:00
--
这块代码加到哪里?
|
-- 作者:有点甜
-- 发布时间:2018/2/28 16:54:00
--
做一个按钮,然后输入代码
http://www.foxtable.com/webhelp/scr/0698.htm
http://www.foxtable.com/webhelp/scr/1064.htm
|
-- 作者:15820092320
-- 发布时间:2018/2/28 16:58:00
--
好的,我试试
|
-- 作者:15820092320
-- 发布时间:2018/2/28 19:57:00
--
这是添加“企业名称”列的一块代码,当我设置第二个大循环准备添加第二列时,为什么提示错误,循环代码基本与这块相同
Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then Dim t As Table = Tables("表B") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("企业名称 = \'" & sheet(n, 0).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim aname As String = sheet(0, i).text If aname > "" AndAlso t.Cols.Contains(aname) Then r(aname) = sheet(n, i).Text End If Next Next For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("纳税人识别号 = \'" & sheet(n, 0).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim bname As String = sheet(0, i).text If bname > "" AndAlso t.Cols.Contains(bname) Then r(bname) = sheet(n, i).Text End If Next Next
t.ResumeRedraw() End If
|
-- 作者:有点甜
-- 发布时间:2018/2/28 21:25:00
--
Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then Dim t As Table = Tables("表B") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("企业名称 = \'" & sheet(n, 0).text & "\' and 纳税人识别号 = \'" & sheet(n, 1).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim aname As String = sheet(0, i).text If aname > "" AndAlso t.Cols.Contains(aname) Then r(aname) = sheet(n, i).Text End If Next Next
t.ResumeRedraw() End If
|