首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

BCB多线程读取数据库,该怎么处理

2012-04-09 
BCB多线程读取数据库C/C++ code#include vcl.h#pragma hdrstop#include Unit1.h#include Unit2.h#pr

BCB多线程读取数据库

C/C++ code
#include <vcl.h>#pragma hdrstop#include "Unit1.h"#include "Unit2.h"#pragma package(smart_init)__fastcall xtheadm::xtheadm(bool CreateSuspended)    : TThread(CreateSuspended){}void __fastcall xtheadm::Execute(){    TADOConnection *ADOConnection1;    TADOQuery *ADOQuery1;    ADOConnection1=new TADOConnection(Application);    ADOQuery1 = new TADOQuery(Application);    ADOConnection1->ConnectionString="Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=swfcf;Data Source=My_Computer";    ADOQuery1->Connection=ADOConnection1;    ADOQuery1->Close();    ADOQuery1->SQL->Clear();    ADOQuery1->SQL->Add("select * from swpr");    ADOQuery1->Open();    while(!ADOQuery1->Eof)    {        Form1->Memo1->Lines->Add(ADOQuery1->Fields->Fields[2]->AsString);    }                                                                        ADOQuery1->Close();    ADOQuery1->Close();}

编译成功,但是执行后,Memo1什么也不显示,请问是哪里错了?

[解决办法]
while(!ADOQuery1->Eof)
{

Form1->Memo1->Lines->Add(ADOQuery1->Fields->Fields[2]->AsString);
ADOQuery1->Next(); //可能就是他
}
[解决办法]
把连接串换成你的试试看,我测试的这个是可以的
C/C++ code
void __fastcall test::Execute(){    //---- Place thread code here ----    CoInitialize(NULL);    TADOConnection *ADOConnection1;    TADOQuery *ADOQuery1;    ADOConnection1=new TADOConnection(Application);    ADOQuery1 = new TADOQuery(Application);    ADOConnection1->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data source="+ExtractFilePath(Application->ExeName)+"test.mdb";    ADOConnection1->LoginPrompt = false;    ADOConnection1->KeepConnection = true;    ADOConnection1->Connected = true;    ADOQuery1->Connection=ADOConnection1;    ADOQuery1->SQL->Clear();    ADOQuery1->SQL->Add("select * from mytable1");    ADOQuery1->Open();while(!ADOQuery1->Eof)    {        Form1->Memo1->Lines->Add(ADOQuery1->Fields->Fields[2]->AsString);        ADOQuery1->Next();    }    ADOQuery1->Close();   delete  ADOQuery1;   delete ADOConnection1;   CoUninitialize();} 

热点排行