以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  只复制排序后前10行的数据  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=118699)

--  作者:蓝蚂蚁
--  发布时间:2018/5/9 9:29:00
--  只复制排序后前10行的数据
我有一个表【窗口1_Table1】按:Tables("窗口1_Table1").sort="总数量 DESC" 排序后 通过代码复制前10行到【表2】,
复制的代码如下:
If MessageBox.Show("是否复制数据?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=DialogResult.Yes Then
    For i As Integer = 0 To 9
        Dim f As New Filler
        f.SourceTable = Tables("窗口1_Table1") \'指定数据来源
        f.SourceCols = "名称,厂家,计价单位,总数量,总金额" \'指定数据来源列
        f.DataTable = DataTables("表2") \'指定数据接收表
        f.DataCols = "名称,厂家,计价单位,数量,金额" \'指定数据接收列
        f.ExcludeExistValue = True
        f.Distinct =True
        f.Fill() \'填充数据        
    Next
End If
但发现是把【窗口1_Table1】所有的数据都复制到表2,请问老师,正确的代码如何编写。谢谢

--  作者:有点甜
--  发布时间:2018/5/9 9:56:00
--  

If MessageBox.Show("是否复制数据?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=DialogResult.Yes Then
    Dim t1 As Table = Tables("窗口1_Table1") \'指定数据来源
   
    Dim t2 As DataTable = DataTables("表2") \'指定数据接收表
    Dim cs1 = "名称,厂家,计价单位,总数量,总金额".split(",")
    Dim cs2 = "名称,厂家,计价单位,数量,金额".split(",") \'指定数据接收列
   
    For i As Integer = 0 To 9
        Dim ndr As DataRow = t2.AddNew
        For j As Integer = 0 To cs1.length-1
            ndr(cs2(j)) = t1.rows(i)(cs1(j))
        Next
    Next
End If

 

[此贴子已经被作者于2018/5/9 10:49:57编辑过]

--  作者:蓝蚂蚁
--  发布时间:2018/5/9 10:37:00
--  
提示错误,看不懂是什么意思?是两个表的数据类型的问题吗?
重载决策失败,因为没有 Public“Item”可以用这些参数调用:
    \'Public Property Item(Col As Integer) As System.Object\':
        与参数“Col”匹配的参数无法从“String()”转换为“Integer”。
    \'Public Property Item(Column As Foxtable.Col) As System.Object\':
        与参数“Column”匹配的参数无法从“String()”转换为“Col”。
    \'Public Property Item(ColumnName As String) As System.Object\':
        与参数“ColumnName”匹配的参数无法从“String()”转换为“String”。

--  作者:有点甜
--  发布时间:2018/5/9 10:50:00
--  

If MessageBox.Show("是否复制数据?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=DialogResult.Yes Then
    Dim t1 As Table = Tables("窗口1_Table1") \'指定数据来源
   
    Dim t2 As DataTable = DataTables("表2") \'指定数据接收表
    Dim cs1 = "名称,厂家,计价单位,总数量,总金额".split(",")
    Dim cs2 = "名称,厂家,计价单位,数量,金额".split(",") \'指定数据接收列
   
    For i As Integer = 0 To 9
        Dim ndr As DataRow = t2.AddNew
        For j As Integer = 0 To cs1.length-1
            ndr(cs2(j)) = t1.rows(i)(cs1(j))
        Next
    Next
End If