以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  代码不能返回正确的值,如何改写?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=11614)

--  作者:yanzhen2010
--  发布时间:2011/8/4 19:12:00
--  代码不能返回正确的值,如何改写?

 

 

If e.DataCol.Name = "拼音码" Then
    If e.NewValue Is Nothing Then
        e.DataRow("项目类别")= Nothing
        e.DataRow("项目名称") = Nothing
    Else
        Dim lb As DataRow
        lb = DataTables("收费项目").Find("[拼音码] = \'" & e.NewValue & "\'")
        If lb IsNot Nothing Then
            e.DataRow("项目类别") = lb("项目类别")
            e.DataRow("项目名称") = lb("项目名称")
        End If      
    End If
End If


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

上面的代码只有"拼音码" 为Nothing时"项目类别"、"项目名称"为Nothing。

另一种情况如果 不匹配,则"项目类别"、"项目名称"依然是原来的值不变。
要求:如果"拼音码"匹配,从“收费项目”找出"项目类别"、"项目名称"并填入,否则"项目类别"、"项目名称"为空。

 

下面是我写的代码,有错误,具体不知如何写,反正是不需进行空值判断,只要本表和“收费项目”表之间拼音码不匹配和“收费项目”表之间拼音码不匹配"为空值。

If e.DataCol.Name = "拼音码" Then
    Dim dr As NewValue=e.DataCol.[拼音码]
    Dim lb As DataRow
    lb = DataTables("收费项目").Find("[拼音码] = \'" & NewValue & "\'")
    If dr= lb
        e.DataRow("项目类别") = lb("项目类别")
        e.DataRow("项目名称") = lb("项目名称")
    End If
End If

 

 

 

问题基本解决,请高手斧正:

If e.DataCol.Name = "拼音码" Then
    Dim lb As DataRow
    lb = DataTables("收费项目").Find("[拼音码] = \'" & e.NewValue & "\'")
    If lb IsNot Nothing Then
        e.DataRow("项目类别") = lb("项目类别")
        e.DataRow("项目名称") = lb("项目名称")
    Else
        e.DataRow("项目类别") = Nothing
        e.DataRow("项目名称") = Nothing
    End If
End If

 

"拼音码"和“收费项目”表的拼音码匹配,"项目类别"、"项目名称"填入,否则Nothing

[此贴子已经被作者于2011-8-4 21:50:15编辑过]

--  作者:czy
--  发布时间:2011/8/4 21:47:00
--  
If e.DataCol.Name = "拼音码" Then
    Dim lb As DataRow
    lb = DataTables("收费项目").Find("[拼音码] = \'" & e.NewValue & "\'")
    If lb IsNot Nothing Then
        e.DataRow("项目类别") = lb("项目类别")
        e.DataRow("项目名称") = lb("项目名称")
    Else
        e.DataRow("项目类别") = Nothing
        e.DataRow("项目名称") = Nothing
    End If
End If

--  作者:yanzhen2010
--  发布时间:2011/8/4 21:53:00
--  
谢谢我也刚想出来,通过比较,看来是正确的。