Foxtable(狐表)用户栏目专家坐堂 → [分享]簡拼模糊查詢


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

主题:[分享]簡拼模糊查詢

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


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/8/24 10:51:00 [显示全部帖子]

沙发

图片点击可在新窗口打开查看


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


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/8/30 15:11:00 [显示全部帖子]

Dim t As Table =Tables("模糊查询_Table1")
Dim py,Lm,Ts, Bm,sql,Lb,sl As String
Dim Ls As New List(Of Integer)
Dim Lss As New List(Of String)
Static st As String

Dim drs As New List(of DataRow)                        '定义一个DataRow行的集合
Ts = "编号,姓名,部门,职务"                                    '查询相关列
Bm = "员工"
If st = e.sender.Text.ToUpper Then
    Return
Else
   st = e.sender.Text.ToUpper
End If   
e.sender.Text =  st
Sendkeys.Send("^{END}")                                    '光标定于输入框最后

drs = DataTables(Bm).Select("姓名 > ''")
'赋值drs=员工表--姓名列不为空的 DataRow行
If drs.count > 0 Then                                             '如drs行数>0,执行...
    If st IsNot Nothing Then                                    '如输入框内容不为空,执行...
        For Each Lm In Ts.split(",")                            '遍历查询相关列
            For Each dr As DataRow In drs                   '遍历所有行
                py = GetPY(dr(Lm),True)                       '赋值py = 查询行查询列的简拼
                If dr(Lm).IndexOf(st)> -1 OrElse py.IndexOf(st) > -1 Then
                                                                              '如查询行查询列内容(或简拼)包含输入框内容,执行...
                    If Ls.Contains(dr("_Identify")) = False Then    '如不包含则增加
                        ls.Add(dr("_Identify"))
                    End If                  
                    If Lss.Contains(dr(Lm)) = False Then
                        Lss.Add(dr(Lm))
                    End If
                   
                End If
            Next
        Next
        If Ls.count > 0 Then
            For Each n As Integer In Ls
                sql+ = ","  & n                                                            
            Next
            sql = "[_Identify] In(" & sql.Trim(",") & ")"                            '包含主键[_Identify]内容
            sql = "select " & Ts & " from{" & Bm & "} where " & sql          '合成SQL语句
            t.Fill(sql,True)                                                                    '生成SQL查询表
            For Each sl In Lss
                lb+ = "|"  & sl
            Next
            e.sender.ComboList = lb                                                      '形成输入框列表
        Else
            MessageBox.show("抱歉,数据库中没有您想查询的信息!" )
            'e.sender.value =  ""
            e.sender.Select
            Return          
        End If     
    End If
End If


 回到顶部