以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 跨表引用问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=172735) |
-- 作者:lgz518 -- 发布时间:2021/10/28 14:31:00 -- 跨表引用问题 需求:“表A”录入完成数据,从“表B”的“货号,品名”录找相应的数据,生成“表C”数据。如下图 这个类于帮助BOM的实例,它是汇总起来,下面的需求是明细,不汇总。 下面代码只实现单条,没办法实现图,表C的结果,如何实现表C的结果? If e.DataCol.Name = "货名" Then \'如果内容发生变动的是品名列 If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空 e.DataRow("料名") = Nothing \'那么清空此行单价列的内容 Else Dim dr As DataRow \'否则在产品表查找同名的产品行,将找到的行赋值给变量dr dr = DataTables("表B").Find("[货名 = \'" & e.NewValue & "\'") If dr IsNot Nothing Then \'如果找到了同名的产品行,也就是dr不是Nothing e.DataRow("料名") = dr("料名") End If End If End If |
-- 作者:有点蓝 -- 发布时间:2021/10/28 14:37:00 -- DataTables("表B").Find改为DataTables("表B").Select |
-- 作者:lgz518 -- 发布时间:2021/10/28 15:43:00 -- 老师,下面代码,不执行,无法实现上面需求,如何解决?谢谢 If e.DataCol.Name = "货名" Then \'如果内容发生变动的是品名列 If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空 e.DataRow("料号") = Nothing \'那么清空此行单价列的内容 e.DataRow("料名") = Nothing e.DataRow("用量") = Nothing Else \'Dim dr As DataRow \'\'否则在产品表查找同名的产品行,将找到的行赋值给变量dr \'dr = DataTables("表B").Find("[货名 = \'" & e.NewValue & "\'") Dim Cols1() As String = {"料号","料名","用量"} Dim Cols2() As String = {"料号","料名","用量"} For Each dr1 As DataRow In DataTables("表B").Select("[货名 = \'" & e.NewValue & "\'") Dim dr2 As DataRow = DataTables("表C").AddNew() For i As Integer = 0 To Cols1.Length -1 dr2(Cols2(i)) = dr1(Cols1(i)) Next Next End If End If
|
-- 作者:有点蓝 -- 发布时间:2021/10/28 15:50:00 -- Dim Cols1() As String = {"货号","品名","料号","料名","用量"} Dim Cols2() As String = {"货号","品名","料号","料名","用量"} For Each dr1 As DataRow In DataTables("表B").Select("[货名 = \'" & e.NewValue & "\'") Dim dr2 As DataRow = DataTables("表C").AddNew() For i As Integer = 0 To Cols1.Length -1 dr2(Cols2(i)) = dr1(Cols1(i)) Next dr2("数量") = e.DataRow("数量") Next |
-- 作者:lgz518 -- 发布时间:2021/10/28 16:34:00 -- 老师,没报错,就是不执行 If e.DataCol.Name = "货名" Then \'如果内容发生变动的是品名列 If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空 e.DataRow("料号") = Nothing \'那么清空此行单价列的内容 e.DataRow("料名") = Nothing e.DataRow("用量") = Nothing Else \'Dim dr As DataRow \'\'否则在产品表查找同名的产品行,将找到的行赋值给变量dr \'dr = DataTables("表B").Find("[货名 = \'" & e.NewValue & "\'") Dim Cols1() As String = {"货号","品名","料号","料名","用量"} Dim Cols2() As String = {"货号","品名","料号","料名","用量"} For Each dr1 As DataRow In DataTables("表B").Select("[货名 = \'" & e.NewValue & "\'") Dim dr2 As DataRow = DataTables("表C").AddNew() For i As Integer = 0 To Cols1.Length -1 dr2(Cols2(i)) = dr1(Cols1(i)) Next dr2("数量") = e.DataRow("数量") Next End If End If
|
-- 作者:有点蓝 -- 发布时间:2021/10/28 16:52:00 -- 重置一下货名列 |
-- 作者:lgz518 -- 发布时间:2021/10/28 17:18:00 -- 重置一下货名列,也无效果 |
-- 作者:有点蓝 -- 发布时间:2021/10/28 17:19:00 -- 列的名称是货名还是货号? |
-- 作者:lgz518 -- 发布时间:2021/10/28 17:45:00 -- If e.DataCol.Name = "货号" Then \'如果内容发生变动的是品名列 If e.NewValue Is Nothing Then \'如果新值是空白,也就是品名列的内容为空 e.DataRow("料号") = Nothing \'那么清空此行单价列的内容 e.DataRow("料名") = Nothing e.DataRow("用量") = Nothing Else \'Dim dr As DataRow \'\'否则在产品表查找同名的产品行,将找到的行赋值给变量dr \'dr = DataTables("表B").Find("[货名 = \'" & e.NewValue & "\'") Dim Cols1() As String = {"货号","品名","料号","料名","用量"} Dim Cols2() As String = {"货号","品名","料号","料名","用量"} For Each dr1 As DataRow In DataTables("表B").Select("[货号= \'" & e.NewValue & "\'") Dim dr2 As DataRow = DataTables("表C").AddNew() For i As Integer = 0 To Cols1.Length -1 dr2(Cols2(i)) = dr1(Cols1(i)) Next dr2("数量") = e.DataRow("数量") Next End If End If 是货号,改过来,执行报错: .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2021.5.29.1 错误所在事件:表,表C,DataColChanged 详细错误信息: 调用的目标发生了异常。 表达式包含无效名称:“[货号= \'A-01\'”。
|
-- 作者:lgz518 -- 发布时间:2021/10/28 17:49:00 -- 货号字段是字符型,不是表达式列 |