Foxtable(狐表)用户栏目专家坐堂 → [求助]填充数据


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

主题:[求助]填充数据

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/12/24 15:06:00 [显示全部帖子]

 第一个问题:Datatables("xxx").DataRows.Clear

 第二个问题:排除重复行,修改一下sql语句;或者是用find方法。(下面使用find方法)


Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * From {库存明细} a Where 工程简称 = '" & QJDM工程简称 & "' And 工程简称 = Order By 录入时间 Desc"
Dim Cols1() As String = {"工程简称","材料类别","二级类别","材料名称","品牌","型号","规格","色号","单位","单价","库存数量","录入时间"}
Dim Cols2() As String = {"工程简称","材料类别","二级类别","材料名称","品牌","型号","规格","色号","单位","单价","库存数量","录入时间"}
dt = cmd.ExecuteReader()
For Each dr1 As DataRow In dt.DataRows
    if DataTables("实时库存").Find("工程简称 = '" & dr1("工程简称") & "' And 材料类别 = '" & dr1("材料类别") & "'") Is nothing  Then
        Dim dr2 As DataRow = DataTables("实时库存").AddNew()
        For i As Integer = 0 To Cols1.Length -1
            dr2(Cols2(i)) = dr1(Cols1(i))
        Next
    End If
Next

[此贴子已经被作者于2012-12-24 16:04:52编辑过]

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/12/24 16:04:00 [显示全部帖子]

刚才那段写错了,注意红色的代码,替换成你的条件就行了
 
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * From {库存明细} a Where 工程简称 = '" & QJDM工程简称 & "' And 工程简称 = Order By 录入时间 Desc"
Dim Cols1() As String = {"工程简称","材料类别","二级类别","材料名称","品牌","型号","规格","色号","单位","单价","库存数量","录入时间"}
Dim Cols2() As String = {"工程简称","材料类别","二级类别","材料名称","品牌","型号","规格","色号","单位","单价","库存数量","录入时间"}
dt = cmd.ExecuteReader()
For Each dr1 As DataRow In dt.DataRows
    if DataTables("实时库存").Find("工程简称 = '" & dr1("工程简称") & "' And 材料类别 = '" & dr1("材料类别") & "'") is nothing Then '在实时库存没有查找到
        Dim dr2 As DataRow = DataTables("实时库存").AddNew()
        For i As Integer = 0 To Cols1.Length -1
            dr2(Cols2(i)) = dr1(Cols1(i))
        Next
    End If
Next

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/12/24 17:02:00 [显示全部帖子]

 你的代码是怎样写的?

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/12/24 17:22:00 [显示全部帖子]

 前面加一个空格,变成 "'  order by 录入时间 desc"

 回到顶部