以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]如何根据两列跨表取值赋值? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=146724) |
||||
-- 作者:yangheqing -- 发布时间:2020/3/1 8:50:00 -- [求助]如何根据两列跨表取值赋值? 根据帮助,论坛中的例子,一直没有处理好。 1、现在,如果只查找其中的一个可以将值赋给角色权限描述, 2、如果同时查找两个,其中一个不变化,如何赋值 3,如果只找到一个,如何将其中的一个赋值。 Dim s1,s2,s3 As String If e.DataCol.Name = "角色ID" Then \'如果内容发生变动的是角色ID Dim dr1 As DataRow If e.DataRow.IsNull("角色ID") And e.DataRow.IsNull("权限ID") Then \'如果新值是空白,也就是角色ID列的内容为空 e.DataRow("角色权限描述") = Nothing \'那么清空此行角色权限描述的内容 Else \'否则在角色表查找同名的角色ID行,将找到的行赋值给变量dr1 dr1 = DataTables("角色").Find("[角色ID] = \'" & e.NewValue & "\'") If dr1 IsNot Nothing Then \'如果找到了同名的角色ID行,也就是dr不是Nothing e.DataRow("角色权限描述") = dr1("角色名") & s1 & "_" s1 = e.DataRow("角色权限描述") End If End If End If If e.DataCol.Name = "权限ID" Then If e.DataCol.Name = "角色ID" And e.DataRow.IsNull("权限ID") Then \'如果内容发生变动的是权限ID If e.NewValue Is Nothing Then \'如果新值是空白,也就是角色ID列的内容为空 s1 = e.DataRow("角色权限描述") \'那么清空此行角色权限描述的内容 e.DataRow("角色权限描述") = Nothing End If Else Dim dr2 As DataRow \'否则在角色表查找同名的角色ID行,将找到的行赋值给变量dr dr2 = DataTables("权限").Find("[权限ID] = \'" & e.NewValue & "\'") If dr2 IsNot Nothing Then \'如果找到了同名的角色ID行,也就是dr不是Nothing s2 = dr2("权限名") e.DataRow("角色权限描述") = s1 & s2 End If End If End If 权限ID取值权限名不变化。 Select Case e.DataCol.Name Case "角色ID","权限ID" Dim s As String = e.DataRow("角色ID") Dim dr1 As DataRow = DataTables("角色").Find("角色ID = " & e.DataRow("角色ID")) If dr1 IsNot Nothing Then s = s & dr1("角色名") & "_" else e.DataRow("角色权限描述") = "" End If Dim dr2 As DataRow = DataTables("权限").Find("权限ID = " & e.DataRow("权限ID")) If dr2 IsNot Nothing Then e.DataRow("角色权限描述") = s & dr2("权限名") End If End Select 其中不允许为空值。 |
||||
-- 作者:狐狸爸爸 -- 发布时间:2020/3/1 16:22:00 -- Select Case e.DataCol.Name Case "角色ID","权限ID" Dim dr1 As DataRow = DataTables("角色").Find("角色ID = " &
e.DataRow("角色ID")) Dim dr2 As DataRow = DataTables("权限").Find("权限ID = " &
e.DataRow("权限ID")) If dr1 Is Nothing And dr2 Is Nothing Then \'如果两个都不存在 e.DataRow("角色权限描述")
= Nothing Else \'否则 Dim
s As String = e.DataRow("角色ID") If dr1 IsNot Nothing Then \'如果角色不存在 s = s & dr2("权限名") ElseIf
dr2 Is Nothing \'如果权限名不存在 s
= s & dr1("角色名") &
"_" Else
\'剩下就是两个都存在 s
= s & dr1("角色名") &
"_" &
dr2("权限名") End
If e.DataRow("角色权限描述")
= s End If End Select |
||||
-- 作者:yangheqing -- 发布时间:2020/3/1 17:41:00 -- 调用的目标发生了异常 还是出不来,输入角色ID时发生调用错误,取消后再输入权限ID时权限名拼接成功,但用户名没有。如图 [此贴子已经被作者于2020/3/1 18:52:12编辑过]
|
||||
-- 作者:yangheqing -- 发布时间:2020/3/1 17:44:00 -- 如图 |
||||
-- 作者:yangheqing -- 发布时间:2020/3/1 20:19:00 -- .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2020.3.2.8 错误所在事件:表,角色权限,DataColChanged 详细错误信息: 调用的目标发生了异常。 语法错误:“=”运算符后缺少操作数。
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/1 20:59:00 -- Select Case e.DataCol.Name Case "角色ID","权限ID" Dim s As String = "" Dim dr1 As DataRow = DataTables("角色").Find("角色ID = " & e.DataRow("角色ID")) If dr1 IsNot Nothing Then s = s & dr1("角色名") & "_" End If Dim dr2 As DataRow = DataTables("权限").Find("权限ID = " & e.DataRow("权限ID")) If dr2 IsNot Nothing Then s = s & dr2("权限名") End If If s > "" Then e.DataRow("角色权限描述") = s Else e.DataRow("角色权限描述") = Nothing End If End Select
|
||||
-- 作者:yangheqing -- 发布时间:2020/3/2 9:54:00 -- 老师,还是出错,您测试一下试试。 |
||||
-- 作者:yangheqing -- 发布时间:2020/3/2 9:58:00 -- ![]() ![]() 为什么上传附件不成功
|
||||
-- 作者:yangheqing -- 发布时间:2020/3/2 10:05:00 --
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/2 10:23:00 -- 建议统一一下ID,有些是整数,有些又是字符 Select Case e.DataCol.Name Case "角色ID","权限ID" Dim s As String = "" If e.DataRow.IsNull("角色ID") = False Dim dr1 As DataRow = DataTables("角色").Find("角色ID = \'" & e.DataRow("角色ID") & "\'") If dr1 IsNot Nothing Then s = s & dr1("角色名") End If End If If e.DataRow.IsNull("权限ID") = False Dim dr2 As DataRow = DataTables("权限").Find("权限ID = " & e.DataRow("权限ID")) If dr2 IsNot Nothing Then If s > "" Then s = s & "_" s = s & dr2("权限名") End If End If If s > "" Then e.DataRow("角色权限描述") = s Else e.DataRow("角色权限描述") = Nothing End If End Select |