以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请教!代码优化?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=130146)

--  作者:lk15502
--  发布时间:2019/1/14 16:25:00
--  请教!代码优化?
有两个表,一个“配缸表”,另一个“成品入库表”;两个表都有“缸号”列;加入“配缸表”产生10000个缸号;最后在“成品入库表”只有9000个缸号,想用代码把1000个没有入到“成品入库表”的缸号找出来,写了下面的代码,可以找到但是要10几秒时间,请老师帮我看看有更好的代码写法;谢谢!table5就是“配缸表”
Dim ghkt As WinForm.TextBox = e.Form.Controls("缸号开头")
Dim kcbs As String = DataTables("成品入库表").SQLGetComboListString("缸号","[缸号] like \'" & ghkt.text & "%\' and [缸号] is not null")
kcbs = "(\'" & kcbs.replace("|","\',\'") & "\')"
\'-------历遍成品入库表的缸号生成集合-------
DataTables(e.Form.Name & "_table5").LoadFilter = "_identify is not null"
DataTables(e.Form.Name & "_table5").Load
Dim ckbs As String = DataTables(e.Form.Name & "_table5").GetComboListString("缸号","[配缸] = 1 and [缸号] like \'" & ghkt.text & "%\' And [缸号] not In " & kcbs)
ckbs = "(\'" & ckbs.replace("|","\',\'") & "\')"
DataTables(e.Form.Name & "_table5").LoadFilter = "[缸号] in " & ckbs
DataTables(e.Form.Name & "_table5").Load


--  作者:有点甜
--  发布时间:2019/1/14 16:36:00
--  

尝试直接写sql语句,比如

 

Dim sql语句 = "select * from {配缸表} where 缸号 not in (select 缸号 from {成品入库表} where 缸号 is not null)"

Tables(e.Form.Name & "_table5").fill(sql语句,"数据源",false)


--  作者:lk15502
--  发布时间:2019/1/14 16:41:00
--  
甜老师,能写详细一点吗?没有写过SQL语句


--  作者:lk15502
--  发布时间:2019/1/14 17:02:00
--  
like怎么写到SQL


--  作者:有点甜
--  发布时间:2019/1/14 17:03:00
--  

比如

 

Dim sql语句 = "select * from {配缸表} where 缸号 not in (select 缸号 from {成品入库表} where 缸号 is not null and 缸号 like \'" & ghkt.text & "%\')"


--  作者:lk15502
--  发布时间:2019/1/14 17:30:00
--  
试了,真的很快!