ACCESS数据库速度问题
在DataModule1用3个TADOTable控件和1个TADOConnection控件,TADOTable分别关联TB、TS、TRef ACCESS表。其目的就是要将3张表中的相关信息放到IB结构中。TB大约3000记录,TS大约3000记录 ,TRef 大约50000记录,代码如下:
大约需要16分钟简直让人无法忍受啊,请大家看看,是代码的问题还是方法问题?如何提高速度,谢谢!
DataModule1->TB->Open();
DataModule1->TS->Open();
DataModule1->TRef->Open();
DataModule1->TB->Filter = "type = 'DX'";
DataModule1->TB->Filtered = true;
int Count = DataModule1->TB->RecordCount;
j=0;
for ( i=0;i<Count;i++) //Count大约2000左右
{
SigOff = 0;
IB[i].Name = DataModule1->TB->FieldByName("name")->AsString ;
IB[i].Type = DataModule1->TB->FieldByName("Type")->AsString ;
IB[i].Max = DataModule1->TB->FieldByName("max")->AsString ;
IB[i].Perd = DataModule1->TB->FieldByName("perd")->AsString ;
IB[i].Ser = DataModule1->TB->FieldByName("ser")->AsString ;
IB[i].Explain = DataModule1->TB->FieldByName("label")->AsString ;
IB[i].Note = DataModule1->TB->FieldByName("description")->AsString;
DataModule1->TRef->Filter = "id = '" + IntToStr(i) +"'";
DataModule1->TRef->Filtered = true;
DataModule1->TRef->Sort = "offset ASC";
while(!DataModule1->TRef->Eof)
{
if(DataModule1->TRef->FieldByName("id")->AsString != "")
{
int SN = DataModule1->TRef->FieldByName("id")->AsInteger;
IB[i].Ref[j].SigRef = Base2SignalNum(SN);
IB[i].Ref[j].SizeOffset = SigOff;
j++;
DataModule1->TS->First();
DataModule1->TS->Filter = "id = '" + IntToStr(SN) +"'";
DataModule1->TS->Filtered = true;
SigOff = SigOff + DataModule1->TS->FieldByName("size")->AsInteger/8;
DataModule1->TS->Filtered = false;
}
DataModule1->TRef->Next();
}
IB[i].SigNum = j;
DataModule1->TB->Next();
}
DataModule1->TB->Filtered = false;
DataModule1->TRef->Filtered = false;
DataModule1->TB->Close();
DataModule1->TS->Close();
DataModule1->TRef->Close();
[解决办法]
方便的話把你的access表,把表聯連的規則用語言表達清楚發我郵箱.shengjie4945@sina.com.cn