Foxtable(狐表)用户栏目专家坐堂 → fill的用法疑问


  共有13817人关注过本帖树形打印复制链接

主题:fill的用法疑问

帅哥哟,离线,有人找我吗?
唐尸三摆手
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
fill的用法疑问  发帖心情 Post By:2010/9/23 17:48:00 [显示全部帖子]

请教用FILL填充的数据表,能否动态增加一列sn(也就是无重复的连续编号),请教如何生成

 

用了DataCols.Add对吗?


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/24 7:45:00 [显示全部帖子]

C版主请指教一下思路,主要是序列号

 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/24 9:54:00 [显示全部帖子]

由于对生成的数据做二次处理,此过程中要求对每行数据 进行跟踪,如果使用行号列,处理后会导致数据顺序打乱,这样行号列会不会随之改变?

 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/24 14:11:00 [显示全部帖子]

老大,四楼的代码为啥执行完报错,提示该表不存在“序号”列呢?


图片点击可在新窗口打开查看此主题相关图片如下:screenshot1.jpg
图片点击可在新窗口打开查看

 

 

该按钮代码如下:

Dim frmname As String=e.Form.name
Dim tbl1 As datatable = DataTables(frmname & "_table2")
tbl1.DataCols.Add("序号",Gettype(Integer))
For i As Integer = 0 To tbl1.DataRows.count-1
Dim dr As DataRow=tbl1.DataRows(i)
    dr("序号") = i
Next


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/24 15:35:00 [显示全部帖子]

没有,上述代码单独执行是没问题的,但是fill之后的数据表再执行这个代码就报错了


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/24 19:03:00 [显示全部帖子]

Dim frmname As String=e.Form.name
Dim tbl As Table = Tables(frmname & "_table1")
If tbl.GetCheckedRows().count=0 Then
    messagebox.show("请选择工厂订单")
Else
    Dim gcr As List(of Row) = tbl.GetCheckedRows()
    Dim s As String
    For Each r As Row In gcr
        s = s & "'" & r("planid") & "',"
    Next
    Dim cmd As New SQLCommand
    Dim dt As datatable
    cmd.C
    cmd.CommandText = ";with cte As (select aec00000.planid,abe00000.*,cast(abe00000.num as numeric(18,4)) As CalcNum from abe00000 join aec00000 on abe00000.parentitem = aec00000.itemcode join eba00000 on aec00000.id_contract = eba00000.id_contract where aec00000.planid  in (" & s.Trim(",") & ") union all select cte.planid,a.*,cast(a.num * cte.CalcNum as numeric(18,4))from abe00000 a Join cte on a.parentitem  = cte.childitem)select a.planid,d.requiredate,a.parentitem,b.name,a.childitem,c.name,c.unit,a.CalcNum*d.plannum as totalnum from cte a,aaa00000 b,aaa00000 c,aec00000 d where a.parentitem=b.code and a.childitem=c.code and a.planid=d.planid union all select a.planid,a.requiredate,a.itemcode as parentitem,b.name,a.itemcode as childitem,c.name,c.unit,a.plannum as totalnum from aec00000 a,aaa00000 b,aaa00000 c where planid  in (" & s.Trim(",") & ")and a.itemcode=b.code and a.itemcode=c.code"
    dt = cmd.ExecuteReader()
    Tables(frmname & "_table2").Datasource=dt
End If

 

'添加列

Dim tbl1 As datatable = DataTables(frmname & "_table2")
tbl1.DataCols.Add("序号",Gettype(Integer))
For i As Integer = 0 To tbl1.DataRows.count-1
Dim dr As DataRow=tbl1.DataRows(i)
    dr("序号") = i
Next

 

 

 

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/25 7:28:00 [显示全部帖子]

老大,帮忙看一下啦

 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/9/25 9:48:00 [显示全部帖子]

Dim frmname As String=e.Form.name
Dim tbl As Table = Tables(frmname & "_table1")
If tbl.GetCheckedRows().count=0 Then
    messagebox.show("请选择工厂订单")
Else
    Dim gcr As List(of Row) = tbl.GetCheckedRows()
    Dim s As String
    For Each r As Row In gcr
        s = s & "'" & r("planid") & "',"
    Next
    Dim st As String
    st = ";with cte As (select aec00000.planid,abe00000.*,cast(abe00000.num as numeric(18,4)) As CalcNum from abe00000 join aec00000 on abe00000.parentitem = aec00000.itemcode join eba00000 on aec00000.id_contract = eba00000.id_contract where aec00000.planid  in (" & s.Trim(",") & ") union all select cte.planid,a.*,cast(a.num * cte.CalcNum as numeric(18,4))from abe00000 a Join cte on a.parentitem  = cte.childitem)select a.planid,d.requiredate,a.parentitem,b.name,a.childitem,c.name,c.unit,a.CalcNum*d.plannum as totalnum from cte a,aaa00000 b,aaa00000 c,aec00000 d where a.parentitem=b.code and a.childitem=c.code and a.planid=d.planid union all select a.planid,a.requiredate,a.itemcode as parentitem,b.name,a.itemcode as childitem,c.name,c.unit,a.plannum as totalnum from aec00000 a,aaa00000 b,aaa00000 c where planid  in (" & s.Trim(",") & ")and a.itemcode=b.code and a.itemcode=c.code"
    Tables(frmname & "_table2").fill(st,"erp",True)
End If

 

 

 

 

怪事,改成fill后又可以附加那段添加序号列的代码了,原来可不是这样的,总提示什么

 

 

不支持基于sqlcommand生成的没有基表的数据什么的


 回到顶部