以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何组合?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=188086)

--  作者:lin98
--  发布时间:2023/8/31 16:31:00
--  如何组合?
如何将下面二个代码组合一起?
代码一
Dim db = HySq-l.DataBaseFactory.CreateDatabase("myjc")
Dim Sql2 = "Selec-t a.单号,a.编号, a.品名,  a.单位, a.数量,b.供方, b.采购日期, b.制单人,b.UserID  From cgmx a Inner Join cgzb b On (a.采购单号 = b.采购单号)"
Dim dt2 As system.data.DataTable = db.ExecuteDataSet(Sq-l2).Tables(0)
Dim t2 As Table = e.Form.Controls("Table1").Table
t2.datasource = dt2.Copy
t2.AllowEdit = False 

代码二
Dim Filter As String = "{窗口_Table1}.制单人=\'" & _Username & "\'  "
Dim dr2 As DataRow
dr2 = DataTables("Users").Find("[Group] = \'" & _UserGroup & "\'")
Dim s As String
If dr2 IsNot Nothing Then
    s = dr2("Xjry")
    If s > "" Then
        Filter = Filter & " or {窗口_Table1}.UserID in (" & s.Replace(",", ",") & ")"
        
    End If 
End If
msgbox(Filter)
DataTables("窗口_Table1").LoadFilter = Filter \'
DataTables("窗口_Table1").Load()
[此贴子已经被作者于2023/8/31 16:32:30编辑过]

--  作者:有点蓝
--  发布时间:2023/8/31 16:50:00
--  
没有办法组合,要想加条件重新加载数据,只能使用代码一

SQL加条件大概这样
Dim Sql2 = "Selec-t a.单号,a.编号, a.品名,  a.单位, a.数量,b.供方, b.采购日期, b.制单人,b.UserID  From cgmx a Inner Join cgzb b On (a.采购单号 = b.采购单号) where b.制单人= \'" & _Username & "\'  or b.UserID in (" & s.Replace(",", ",") & ")"

--  作者:lin98
--  发布时间:2023/8/31 17:16:00
--  


Dim db = HySq-l.DataBaseFactory.CreateDatabase("myjc")
Dim Sql2 = "Selec-t a.单号,a.编号, a.品名,  a.单位, a.数量,b.供方, b.采购日期, b.制单人,b.UserID  From cgmx a Inner Join cgzb b On (a.采购单号 = b.采购单号) where b.制单人= \'" & _Username & "\'  or b.UserID in (" & s.Replace(",", ",") & ")"
Dim dt2 As system.data.DataTable = db.ExecuteDataSet(Sq-l2).Tables(0)
Dim t2 As Table = e.Form.Controls("Table1").Table
t2.datasource = dt2.Copy
t2.AllowEdit = False 

执行报销:
You have an error in your SQ-L syntax; check the manual that corresponds to your MySQ-L server version for the right syntax to use near \')\' at line 1


[此贴子已经被作者于2023/8/31 18:34:47编辑过]

--  作者:有点蓝
--  发布时间:2023/8/31 17:18:00
--  
or b.UserID in (\'" & s.Replace(",", "\',\'") & "\')"
--  作者:lin98
--  发布时间:2023/8/31 17:30:00
--  
11
[此贴子已经被作者于2023/8/31 18:34:25编辑过]

--  作者:lin98
--  发布时间:2023/8/31 18:13:00
--  
OK
[此贴子已经被作者于2023/8/31 18:32:25编辑过]

--  作者:lin98
--  发布时间:2023/9/11 11:00:00
--  


Dim Sql2 = "Selec-t a.单号,a.编号, a.品名,  a.单位, a.数量,b.供方, b.采购日期, 
b.制单人,b.UserID  From cgmx a Inner Join cgzb b On (a.采购单号 = b.采购单号) where b.制单人= \'" & _Username & "\'  or b.UserID in (\'" & s.Replace(",", "\',\'") & "\')" "\'  



[此贴子已经被作者于2023/9/11 11:26:16编辑过]

--  作者:有点蓝
--  发布时间:2023/9/11 11:19:00
--  
 where (b.制单人= \'" & _Username & "\'  or b.UserID in (\'" & s.Replace(",", "\',\'") & "\')") And  b.采购日期 >= \'" & StartDate & "\' And b.采购日期 <= \'" & EndDate & "\'