以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]从外部表中首拼音查询  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=42809)

--  作者:hzcaqjf
--  发布时间:2013/11/22 16:42:00
--  [求助]从外部表中首拼音查询

先从外部表提取数据生成临时表"dt"

再从临时表中进行某几列的首拼音查询.

下面代码得不到正确结果:

Dim Ts As String() = {"收款单位","付款单位"}
Dim t As Table = Tables("窗口1_table1")
e.Form.controls("table1").Visible = True
e.Form.controls("table2").Visible = False
Dim dtp1 As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")
Dim dtp2 As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker2")
Dim v1 As Date = dtp1.value
Dim v2 As Date = dtp2.value
Dim sql,st,Lm,py,sul As String
Dim Ls As new List(of Integer)
Dim dt As DataTable
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "SELECT * From {表A} where 凭证日期 >= #" & v1 & "# And 凭证日期 <= #" & v2 & "#"
dt = cmd.ExecuteReader( )
Dim sw As String = e.sender.text
st = "\'%" & sw & "%\'"
If sw > "" Then
    For Each Lm In Ts
        For Each dr As DataRow In dt.dataRows \'此处 dt 换成内部表则没问题.
            py = GetPy(dr(Lm),True)
            If dr(Lm).Indexof(sw)> -1 OrElse py.Indexof(sw)> -1 Then
                If Ls.Contains(dr("序号")) = False Then
                    Ls.add(dr("序号"))
                End If
            End If
        Next
    Next
    If Ls.count > 0 Then
        For Each n As Integer In Ls
            sql+ = "," & n
        Next
        sql = "[序号] in (" & sql.trim(",") & ")"
        sul+ = "select 序号,收款单位,付款单位 from (select * from {表A} where" & sql & ")"
        sul+ = "where  收款单位 like" & st & " or 付款单位 like" & st & ""
        t.fill(sul,"yh",True)
        t.AutoSizeCols()
    End If
Else
    If t.Rows.count > 0 Then
        With t
            For i As Integer = .Rows.count-1 To 0 Step -1
                .Rows(i).Delete()
            Next
        End With
    End If
End If

相似的代码在内部表中查询没问题.求指教.

 

[此贴子已经被作者于2013-11-22 16:45:11编辑过]

--  作者:Bin
--  发布时间:2013/11/22 16:50:00
--  
SQL数据源的话,日期部分应该使用单引号,而不是井号
--  作者:hzcaqjf
--  发布时间:2013/11/22 16:55:00
--  

回Bin老师的话,是access数据源


--  作者:Bin
--  发布时间:2013/11/22 16:56:00
--  
上例子吧,纸上不谈兵!
--  作者:lsy
--  发布时间:2013/11/22 17:20:00
--  
GetPy是狐表的取拼音函数,要从外部数据源取拼音,就自己先寻找或编写相关数据库的取拼音函数。
--  作者:hzcaqjf
--  发布时间:2013/11/22 18:40:00
--  
以下是引用lsy在2013-11-22 17:20:00的发言:
GetPy是狐表的取拼音函数,要从外部数据源取拼音,就自己先寻找或编写相关数据库的取拼音函数。

ExecuteReader 生成的临时表不支持GetPy函数?

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:项目2.rar

[此贴子已经被作者于2013-11-22 18:57:00编辑过]

--  作者:有点甜
--  发布时间:2013/11/22 19:24:00
--  
你的代码没有问题

Dim Ts As String() = {"产品","客户"}
Dim t As Table = Tables("窗口1_table1")
Dim dtp1 As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")
Dim dtp2 As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker2")
Dim v1 As Date = dtp1.value
Dim v2 As Date = dtp2.value
Dim sql,st,Lm,py,sul As String
Dim Ls As new List(of Integer)
Dim dt As DataTable
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "SELECT * From {订单} where 日期 >= #" & v1 & "# And 日期 <= #" & v2 & "#"
dt = cmd.ExecuteReader( )
Dim sw As String = e.sender.text
st = "\'%" & sw & "%\'"
If sw > "" Then
    For Each Lm In Ts
        For Each dr As DataRow In dt.dataRows
            py = GetPy(dr(lm),True)
            If dr(Lm).Indexof(sw.ToUpper)> -1 OrElse py.Indexof(sw.ToUpper)> -1 Then
                If Ls.Contains(dr("_Identify")) = False Then
                    Ls.add(dr("_Identify"))
                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(",") & ")"
        sul+ = "select 产品,客户,雇员,单价,数量,日期 from (Select * from {订单} where" & sql & ")"
        t.fill(sul,"yh",True)
        t.AutoSizeCols()
    Else If t.Rows.count > 0 Then
        With t
            For i As Integer = .Rows.count-1 To 0 Step -1
                .Rows(i).Delete()
            Next
        End With
    End If
End If
[此贴子已经被作者于2013-11-22 19:26:44编辑过]