先从外部表提取数据生成临时表"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编辑过]