{ADO查询多线程单元}
unit ADOThread;
interface
uses
Classes,StdCtrls,ADODB;
type TADOThread = class(TThread)
private { Private declarations }
FListBox:TListBox;
FLabel:TLabel; ConnString:WideString;
FSQLString:string; sl:TStrings; procedure UpdateCount;
protected procedure Execute; override;
public constructor Create(SQL:string;LB:TListBox;Lab:TLabel);
end; implementation
uses
unit1,SysUtils,ActiveX;
{ TADOThread } constructor TADOThread.Create(SQL: string; LB: TListBox;Lab:TLabel);
begin
ConnString:=Form1.con1.ConnectionString;
FListBox:=LB;
FLabel:=Lab;
FSQLString:=SQL;
Inherited Create(False);
end; procedure TADOThread.Execute;
var
Qry:TADOQuery;
i:Integer;
begin { Place thread code here }
FreeOnTerminate:=True; sl:=TStringList.Create;
CoInitialize(nil); //必须调用(需Uses ActiveX)
Qry:=TADOQuery.Create(nil);
try
Qry.ConnectionString:=ConnString; //必须有自己的连接
Qry.Close;
Qry.SQL.Clear;
Qry.SQL.Add(FSQLString);
Qry.Open;
FListBox.Clear;
for i := to do //为了执行久点重复历遍数据集101次
begin
Qry.First;
while not Qry.Eof And not Terminated do
begin
//FListBox.AddItem(Qry.Fields[0].asstring,nil);
//FListBox.Items.Add(Qry.Fields[0].asstring);
sl.Add(Qry.Fields[].asstring);
//如果不调用Synchronize,会出现Canvas Does NOT Allow Drawing
//Synchronize(UpdateCount);
Qry.Next;
end;
//Qry.First;
//FListBox.AddItem('*******',nil); //Synchronize(UpdateCount);
end;
Synchronize(UpdateCount);
finally
sl.Free;
Qry.Free;
end;
CoUninitialize;
end; procedure TADOThread.UpdateCount;
begin
//FLabel.Caption:=IntToStr(FListBox.Items.Count);
FListBox.Items.Assign(sl);
FLabel.Caption:=IntToStr(sl.Count);
end; end. unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls; type
TForm1 = class(TForm)
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
lst1: TListBox;
lst2: TListBox;
lst3: TListBox;
cbb1: TComboBox;
cbb2: TComboBox;
cbb3: TComboBox;
btn1: TButton;
qry1: TADOQuery;
con1: TADOConnection;
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
uses ADOThread; procedure TForm1.FormCreate(Sender: TObject);
var
strSQL:string;
begin
strSQL:='select * from tb_student';
qry1.Close;
qry1.SQL.Clear;
qry1.SQL.Add(strSQL);
qry1.Open;
cbb1.Clear;
cbb2.Clear;
cbb3.Clear; //将客户Company和相关CustNo填到ComboBox中
while not qry1.Eof do
begin
//cbb1.AddItem(qry1.Fields[1].asString, TObject(qry1.Fields[0].AsInteger));
cbb1.Items.Add(qry1.fieldbyname('smc').AsString);
qry1.Next;
end;
cbb2.Items.Assign(cbb1.Items);
cbb3.Items.Assign(cbb1.Items); // 默认选中第一个
cbb1.ItemIndex := ;
cbb2.ItemIndex := ;
cbb3.ItemIndex := ;
end; procedure TForm1.btn1Click(Sender: TObject);
const
SQL_CONST='select sxm from tb_student where sxm';
var c1,c2,c3:Integer; s1,s2,s3:string;
begin //取得三个选择框客户的编码
s1:=SQL_CONST+QuotedStr(cbb1.Text);
s2:=SQL_CONST+QuotedStr(cbb2.Text);
s3:=SQL_CONST+QuotedStr(cbb3.Text);//三个线程同时查询
TADOThread.Create(s1,lst1,lbl1);
TADOThread.Create(s2,lst2,lbl2);
TADOThread.Create(s3,lst3,lbl3);
end; end.

ADO多线程数据库查询的更多相关文章

  1. 【转】Delphi多线程学习(9):多线程数据库查询(ADO)

    原文:http://www.cnblogs.com/djcsch2001/articles/2382559.html ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用 ...

  2. 教程-Delphi多线程数据库查询(ADO)

    ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用(CoInitialize was not called):所以,在使用任何dbGo对象前,必须手 调用CoIniti ...

  3. Delphi多线程数据库查询(ADO)

    ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用(CoInitialize was not called):所以,在使用任何dbGo对象前,必须手 调用CoIniti ...

  4. 多线程数据库查询(ADO)

    ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用(CoInitialize was not called):所以,在使用任何dbGo对象前,必须手 调用CoIniti ...

  5. ADO多线程数据库总结

    ADO多线程数据库查询通常会出现以下问题: 1.CoInitialize 没有调用(CoInitialize was not called):所以,在使用任何dbGo对象前,必须手 调用CoIniti ...

  6. ADO.Net 数据库查询

    数据库中的表: VS查询代码: using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  7. android 多线程数据库读写分析与优化

    最新需要给软件做数据库读写方面的优化,之前无论读写,都是用一个 SQLiteOpenHelper.getWriteableDataBase() 来操作数据库,现在需要多线程并发读写,项目用的是2.2的 ...

  8. 转载 50种方法优化SQL Server数据库查询

    原文地址 http://www.cnblogs.com/zhycyq/articles/2636748.html 50种方法优化SQL Server数据库查询 查询速度慢的原因很多,常见如下几种: 1 ...

  9. 利用C#实现分布式数据库查询

    随着传统的数据库.计算机网络和数字通信技术的飞速发展,以数据分布存储和分布处理为主要特征的分布式数据库系统的研究和开发越来越受到人们的关注.但由于其开发较为复杂,在一定程度上制约了它的发展.基于此,本 ...

随机推荐

  1. PowerShell中执行.net类库

    Powershell脚本一个比较强大的功能是可以直接调用.net类库(ps core能调用.net core类库),除了调用系统类库外,也可以调用自己编写的类库,从而扩充我们脚本的功能.本文这里简单的 ...

  2. python 文件夹递归

    import ospath = "F:/new" #文件夹目录datas = []def eachFile(filepath): fileNames = os.listdir(fi ...

  3. C# 绘制矩形方框读写内存类 cs1.6人物透视例子

     封装的有问题 其中方框可能在别的方向可能 会显示不出来建议不要下载了 抽时间我会用纯c#写一个例子的  其中绘制方框文字和直线调用的外部dll采用DX11(不吃CUP)绘制我封装成了DLL命名为 S ...

  4. Java按位运算符之按位取反

    一 数据储存形式 二进制在内存中以补码的形式存在. 补码首位是符号位,0表示该数是正数,1表示该数是负数.   例如:   数值 带符号的二进制原码 (首位表示符号位) 补码 内存中的形式 (*表示无 ...

  5. CAN分帧发送程序说明

    试验平台 仅仅 需要一台主机 一台 周立功 CAN 助手, 一个232 助手就OK ICAN 协议 资源节点地址 电脑 我认为是0x01 51单片机主机的地址 是 0x1f 建立连接的 功能码 是0x ...

  6. P1047 编程团体赛

    转跳点:

  7. idea下maven项目下spring junit 测试用例

    使用idea在编写的类下右键Go->Test或者ctrl+shift+t,点击create new test会在相应目录下创建test类 别写代码如下 @RunWith(value = Spri ...

  8. js加密(十四)mail.yw.gov.cn/ RSA

    1. url: http://mail.yw.gov.cn/ 2. target:登录js 3. 简单分析: 寻找加密js: 3.1 直接寻找加密的参数p是不好找的,所以我们试着去寻找一些更明显的参数 ...

  9. 094-PHP遍历索引数组和关联数组

    <?php $arr=array(63,'abc',45,'hello',3,7,9,'DEF'); //定义一个索引数组 echo '遍历一个索引数组:<br />'; forea ...

  10. 083-PHP的foreach循环

    <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } print_r($a ...