以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]请问怎么写代码能高效从后台获取是否有包含条件的数据?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=134880)

--  作者:zto001
--  发布时间:2019/5/11 12:34:00
--  [求助]请问怎么写代码能高效从后台获取是否有包含条件的数据?
[求助]请问怎么写代码能高效从后台获取是否有包含条件的数据?
我0.5秒就要判断以便,需要高效不影响正常操作。
条件:接收人=登录账户 and 接收时间为空
这是我写的代码,好像有问题。需要怎么改呢?
Dim dr As DataRow
dr = DataTables("信息表").SQLFind("接收人 = \'" & _name & "\' and 接收时间 is null ") 
第二种   \'Dim dr As List(of DataRow)  = DataTables("信息表").SQLSelect("接收人 = \'" & _name & "\' and 接收时间 is null ")
If dr IsNot Nothing Then 

’执行效果
    static i = 0
    If i = 0 Then
        nfi.Icon = new Icon(ProjectPath & "\\001.ico") \'图标地址
        i=1
    Else
        nfi.Icon = new Icon(ProjectPath & "\\002.ico") \'图标地址
        i=0
    End If

End If

--  作者:有点蓝
--  发布时间:2019/5/11 13:43:00
--  
具体有什么问题?

建议使用SQLFind。

--  作者:chnfo
--  发布时间:2019/5/22 21:11:00
--  
试过,只要是查询条件中有is null或者 is not null,执行效率都很低。
可以试试Dim dr As List(of DataRow)  = DataTables("信息表").SQLfind("接收人 = \'" & _name & "\' and 接收时间 = ‘’ ") 
[此贴子已经被作者于2019/5/22 21:12:12编辑过]

--  作者:有点蓝
--  发布时间:2019/5/23 10:05:00
--  
正常,对于数据库来说is null或者 is not null查询不会使用索引,都是全表扫描,数据越多就越慢。所以一般数据库查询尽量避免is null或者 is not null
--  作者:有点甜
--  发布时间:2019/5/23 15:01:00
--  

搜索相关知识,绕过去即可。

 

https://www.baidu.com/baidu?wd=sqlserver+is+null+%E7%B4%A2%E5%BC%95+%E6%95%88%E7%8E%87