我用一个记录集指针读取数据库中的数据,经过计算得到的结果。再用该指针放入该表中的新开辟的字段内。为什么程序进入死循环,并且数据库的大小以大1G之多?如果用另一指针把结果放入新建的一个表中则不会出现这种情况。各位高手,此问题困扰小弟久矣!请不吝赐教!!
我的部分代码如下:
第一种进入死循环的情况:
while(PointCount)
{
PointCount--;

PointData.PointId=m_pRecordset0->GetCollect("PointId");
// if(PointData.PointId==21969)
// AfxMessageBox("stop");

pointdata[0]=m_pRecordset0->GetCollect("X");
pointdata[1]=m_pRecordset0->GetCollect("Y");
pointdata[2]=m_pRecordset0->GetCollect("Z");


tempCord[0]=(pointdata[0]- BoxMinX)/BoxLength_min;
tempCord[1]=(pointdata[1]- BoxMinY)/BoxLength_min;
tempCord[2]=(pointdata[2]- BoxMinZ)/BoxLength_min;
for(int  i=0;i<BoxId_Length;i++)
PointData.BoxId[i]=0;
for( int j=0;j<BoxId_Length;j++)//此处编码时的循环次数还可以改进
{
PointData.BoxId[j]=tempCord[0]&yanma+2*(tempCord[1]&yanma)+4*(tempCord[2]&yanma);
tempCord[0]>>=1;
tempCord[1]>>=1;
tempCord[2]>>=1;
if(PointData.BoxId[j]==0)
PointData.BoxId[j]=8;
}

double boxid=0.0;
for( j=0;j<BoxId_Length;j++)
{
boxid=boxid*10+PointData.BoxId[j];
}


try{
m_pRecordset0->PutCollect("PointId",PointData.PointId);
m_pRecordset0->PutCollect("BoxId",boxid);
m_pRecordset0->Update();
m_pRecordset0->MoveNext();
}
catch(_com_error e)//捕捉异常
{
CString errormessage;
errormessage.Format("创建数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
AfxMessageBox(LPCSTR(bstrSource));
AfxMessageBox(LPCSTR(bstrDescription));

} }
第二中可以应用的情况:
while(PointCount)
{
PointCount--;

PointData.PointId=m_pRecordset0->GetCollect("PointId");
// if(PointData.PointId==21969)
// AfxMessageBox("stop");

pointdata[0]=m_pRecordset0->GetCollect("X");
pointdata[1]=m_pRecordset0->GetCollect("Y");
pointdata[2]=m_pRecordset0->GetCollect("Z");


tempCord[0]=(pointdata[0]- BoxMinX)/BoxLength_min;
tempCord[1]=(pointdata[1]- BoxMinY)/BoxLength_min;
tempCord[2]=(pointdata[2]- BoxMinZ)/BoxLength_min;
for(int  i=0;i<BoxId_Length;i++)
PointData.BoxId[i]=0;
for( int j=0;j<BoxId_Length;j++)//此处编码时的循环次数还可以改进
{
PointData.BoxId[j]=tempCord[0]&yanma+2*(tempCord[1]&yanma)+4*(tempCord[2]&yanma);
tempCord[0]>>=1;
tempCord[1]>>=1;
tempCord[2]>>=1;
if(PointData.BoxId[j]==0)
PointData.BoxId[j]=8;
}

double boxid=0.0;
for( j=0;j<BoxId_Length;j++)
{
boxid=boxid*10+PointData.BoxId[j];
}


try{
m_pRecordset1->AddNew();
m_pRecordset1->PutCollect("PointId",PointData.PointId);
m_pRecordset1->PutCollect("BoxId",boxid);
m_pRecordset1->Update();
m_pRecordset0->MoveNext();
}
catch(_com_error e)//捕捉异常
{
CString errormessage;
errormessage.Format("创建数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
AfxMessageBox(LPCSTR(bstrSource));
AfxMessageBox(LPCSTR(bstrDescription));

} }

解决方案 »

  1.   

    樓主你把這一句注釋了看看還是不是死循环!!
    m_pRecordset0->Update();
      

  2.   

    嗯爲什麽不用while(!(pRst->EndofFile))實現控制呢
      

  3.   

    对不起,各位大哥们,小弟最近不能上网。谢谢各位的建议。我曾经把 m_pRecordset0->Update();注释掉过,但是不管用。
    我用另外一种方法尝试了一下:
     我又新建了一个表,把计算得到的结果放入新建的表中,竟然比放入原来的表中速度快了何止一倍!
    其中原因小弟百思不得其解。请各位大侠指教!!!水银 大哥 PointCount=495323;你的建议很好,我会尝试用的!!