以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教效率  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=116160)

--  作者:hbhb
--  发布时间:2018/3/20 17:14:00
--  请教效率
大师:请问如果我要从后台统计行的数量,是用SQL的ExecuteScalar快?还是生成SQL临时表,再用表的compute快?
--  作者:hbhb
--  发布时间:2018/3/20 18:16:00
--  
下面的语句如何优化
Dim st As Date = Date.Now
Dim mc As String
For Each c As DataCol In DataTables("dtpzzbwb").DataCols
    If c.IsString = True Then
        mc = c.name
        Dim cmd As New SQLCommand
        Dim nm As Integer
        cmd.C
        cmd.CommandText ="Select Count(*) Fr  om {dtpzzbwb} Where " & mc & "  = \'" & "查找的字符" & "\'"
        nm = cmd.ExecuteScalar
        Output.Show(c.name & "-" & nm)
    End If
Next


--  作者:有点甜
--  发布时间:2018/3/20 19:01:00
--  

使用事务,一次性提交

 

http://www.foxtable.com/webhelp/scr/2933.htm

 

或者组合sql语句,一次性查询,不然多次查询会很耗,如

 

Dim st As Date = Date.Now
Dim mc As String
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim str As String = ""
For Each c As DataCol In DataTables("表A").DataCols
    If c.IsString = True Then
        mc = c.name
        str &= "Select Count(*) as 数量 From {表A} Where " & mc & "  = \'" & "查找的字符" & "\' union all "
    End If
Next
str = str.substring(0, str.length-10)
msgbox(str)
cmd.CommandText = str
dt = cmd.ExecuteReader
For i As Integer = 0 To dt.datarows.count-1
    output.show(i & " " & dt.datarows(i)(”数量"))
next


--  作者:hbhb
--  发布时间:2018/3/20 19:10:00
--  
如果用事务,我的代码怎么写?如下对不对?


Try
    Connections().BeginTransaction()
\'开始事务

Dim st As Date = Date.Now
Dim mc As String
For Each c As DataCol In DataTables("dtpzzbwb").DataCols
    If c.IsString = True Then
        mc = c.name
        Dim cmd As New SQLCommand
        Dim nm As Integer
        cmd.C
        cmd.CommandText ="Select Count(*) Fr  om {dtpzzbwb} Where " & mc & "  = \'" & "查找的字符" & "\'"
        nm = cmd.ExecuteScalar
        Output.Show(c.name & "-" & nm)
    End If
Next
Connections("数据源").Commit \'提交事务,所有操作生效
Catch
ex As Exception \'如果出错
    Connections("数据源").Rollback()
\'回滚事务,撤销所有操作

End
Try


--  作者:有点甜
--  发布时间:2018/3/20 19:12:00
--  
参考3楼文字和代码,自行测试。
--  作者:hbhb
--  发布时间:2018/3/20 19:18:00
--  
用   这个或者组合sql语句,一次性查询,不然多次查询会很耗,如

显示查询过于复杂,怎么办?

--  作者:hbhb
--  发布时间:2018/3/20 19:43:00
--  
我的表100多列,怎么查询语句有字数限制?
--  作者:有点蓝
--  发布时间:2018/3/20 20:11:00
--  
那就使用事务呗