{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. HDU3306-Another kind of Fibonacci(矩阵构造)

    Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  2. HihoCoder第八周:状态压缩 一

    1044 : 状态压缩•一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在兑换到了喜欢的奖品之后,便继续起了他们的美国之行,思来想去,他们决定乘坐火车前 ...

  3. python 编写程序输出50以内勾股数,如下图所示,要求每组显示六祖,各组勾股数无重复

    import math n = 0 for a in range(1,49): for b in range(a,49): c = math.ceil(math.sqrt(a**2+b**2)) if ...

  4. Local-Pref(本地优先属性)路由本地优先术

    Local-Pref(本地优先属性)路由本地优先术: ①:抓取感兴趣流量——前缀与访问——prefix and access ②:创建路由地图——router-map ③:第一法则——permit 1 ...

  5. (转载)wchar_t类型和char类型变量相互转换

    转载连接:https://www.cnblogs.com/zhangdewang/p/11420410.html和https://www.cnblogs.com/lanhaicode/p/105742 ...

  6. java核心-多线程(1)-知识大纲

    Thread,整理一份多线程知识大纲,大写意 1.概念介绍 线程 进程 并发 2.基础知识介绍 Java线程类 Thread 静态方法&实例方法 Runnable Callable Futur ...

  7. 实现Comparator 对List<?>进行排序

    首选需要有个Entity类 ,里面有属性有方法 package demo; public class Entity { private String empNo ; private String em ...

  8. UVALive 4287 SCC-Tarjan 加边变成强连通分量

    还是强连通分量的题目,但是这个题目不同的在于,问你最少要添加多少条有向边,使得整个图变成一个强连通分量 然后结论是,找到那些入度为0的点的数目 和 出度为0的点的数目,取其最大值即可,怎么证明嘛... ...

  9. .net微软企业库的事务回滚

    事务是自定义的一个操作序列. 其中的操作要么全部执行要么全部不执行,是一个不可分割的工作单位.通过事务,SQL Server能将逻辑相关的一组操作绑定在一起,以便服务器保持数据的完整性. Databa ...

  10. Java算法练习——盛最多水的容器

    题目链接 题目描述 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) ...