以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]Find(相同年月)的表达式如何写?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=18499)

--  作者:pc005637
--  发布时间:2012/4/15 14:34:00
--  [求助]Find(相同年月)的表达式如何写?

表A为数据接收表,表B为数据输出表。

 

要求,当表A输入"姓名"后,在表B中查找"姓名"相同,"表A日期"和"表B时期"为同年同月时,将表B的"输出1","输出2","输出3"列的内容,填充到表A的"接收1","接收2","接收3"列。

 

请问在DataColChanged事件中,表达式应该如何书写。

 

 

Select Case e.DataCol.Name
    Case "姓名"
        If e.NewValue IsNot Nothing Then
            Dim dr As DataRow

            dr = DataTables("表B").Find("姓名 = \'" & e.DataRow("姓名") & "\'")\'(这行不会写图片点击可在新窗口打开查看  

            If dr IsNot Nothing Then
                e.DataRow("接收1") = dr("输出1")
                e.DataRow("接收2") = dr("输出2")
                e.DataRow("接收3") = dr("输出3")
            End If
        End If
End Select


--  作者:pc005637
--  发布时间:2012/4/15 15:46:00
--  自问自答。
Select Case e.DataCol.Name
    Case "姓名","表A日期"
        If e.NewValue IsNot Nothing Then
            Dim y As Integer = e.DataRow("表A日期").Year
            Dim m As Integer = e.DataRow("表A日期").Month
            Dim d As Integer = Date.DaysInMonth(y,m)
            Dim dr As DataRow
            dr = DataTables("表B").Find("姓名 = \'" & e.DataRow("姓名") & "\' And [表B日期] >= #" & m & "/1/" & y & "# And [表B日期] <= #" & m & "/" & d & "/" & y & "#")
            If dr IsNot Nothing Then
                e.DataRow("接收1") = dr("输出1")
                e.DataRow("接收2") = dr("输出2")
                e.DataRow("接收3") = dr("输出3")
            End If
        End If
End Select