如何优化连接ACCESS的SQL查询语句?
本帖最后由 dzj124 于 2019-6-17 11:17 编辑我有一个问题想请教下大家,我用AU3对ACCESS做查询操作,需要N个查询语句,但我的代码很繁琐,且效率低下,该如何优化?代码下:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <INet.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $i,$accmdb_data_path,$accmdb_data_pws
$accmdb_data_path="Server.accdb"
$accmdb_data_pws="qjcdi"
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &$accmdb_data_path & ";Jet Oledb:Database Password=" & $accmdb_data_pws)
$RS1 =ObjCreate("ADODB.Recordset")
$RS1.ActiveConnection = $addfld
$RS1.Open ("Select rules.rules From rules WHERE text='更新时间'" )
while Not $RS1.eof And Not $RS1.bof
if @error =1 Then ExitLoop
$url1 = $RS1.Fields (0).value
; MsgBox(0, "", $RS.Fields (2).value);显示表第3个数据
$rs1.movenext
WEnd
$rs1.close
$addfld.Close
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &$accmdb_data_path & ";Jet Oledb:Database Password=" & $accmdb_data_pws)
$RS2 =ObjCreate("ADODB.Recordset")
$RS2.ActiveConnection = $addfld
$RS2.Open ("Select rules.rules From rules WHERE text='下载地址'" )
while Not $RS2.eof And Not $RS2.bof
if @error =1 Then ExitLoop
$url2 = $RS2.Fields (0).value
; MsgBox(0, "", $RS.Fields (2).value);显示表第3个数据
$rs2.movenext
WEnd
$rs2.close
$addfld.Close
$i="*"
$adTable="tab1"
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &$accmdb_data_path & ";Jet Oledb:Database Password=" & $accmdb_data_pws)
$RS3 =ObjCreate("ADODB.Recordset")
$RS3.ActiveConnection = $addfld
$RS3.Open ("Select "&$i& " From " &$adTable )
while Not $RS3.eof And Not $RS3.bof
if @error =1 Then ExitLoop
$url3 = $RS3.Fields (2).value
; MsgBox(0, "", $RS.Fields (2).value);显示表第3个数据
$sText = _INetGetSource($url3)
Local $name = StringRegExp($sText, "<h1>(.*?)</h1>", 3)
Local $uptime = StringRegExp($sText, $url1, 3)
Local $dowload = StringRegExp($sText, $url2, 3)
MsgBox(0, '信息 ',$name&@LF&$uptime&@LF&$dowload&@LF&$url3)
$rs3.movenext
WEnd
$rs3.close
$addfld.Close
#cs ____________________________________
例子: 示例
描述: 搜索数据库中的指定字符串,并返回搜索结果
语法: SELECT * FROM " 表名 Where 字段名 = '字符串'
参数: $RS.Fields($adCol).Value = 返回搜索结果
当您首次打开一个 Recordset 时,当前记录指针将指向第一个记录,
同时 BOF 和 EOF 属性为 False。如果没有记录,BOF 和 EOF 属性为 True。
#ce _______________脚本开始_________________
;示例
#AutoIt3Wrapper_UseX64 = n
$readq19 = '下载地址'
$accmdb_data_path="Server.accdb"
$accmdb_data_pws="qjcdi"
$adTable="tab1"
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &$accmdb_data_path & ";Jet Oledb:Database Password=" & $accmdb_data_pws)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT * FROM " & $adTable & " WHERE knamee='" & $readq19 & "' OR knamee2='" & $readq19 & "'OR knamee3='" & $readq19 & "'")
While Not $RS.eof And Not $RS.bof
$re1 = $RS.Fields(1).value
$re2 = $RS.Fields(2).value
$re3 = $RS.Fields(3).value
$RS.movenext
WEnd
$rs.close
$addfld.Close
不错支持一下 chzj589 发表于 2019-6-17 15:50
#cs ____________________________________
例子: 示 ...
非常感谢大神的回复
页:
[1]