{
CDBSystemApp* pApp = (CDBSystemApp*)AfxGetApp();
int i;
try
{
for (i=0;i < pApp->CodeArray.GetSize();i++)
{
CMainFrame *pmain = (CMainFrame*) AfxGetMainWnd();
_RecordsetPtr pRecordset,pRecordset1;
CString list("SELECT * FROM [");
CString list1("]..[");
CString list2("] WHERE 编码 =");
list = list + pApp->m_CopyDB + list1 +pApp->m_CopyDB + list2 + "'"+pApp->CodeArray.GetAt(i)+"'";
_variant_t vComponentType,vCode,vSummary,
vComponentBoundary,
vOperatingMode,vOperatingEnvironment,
vReliabilityModel,vFailureDistribution,vFM,
vFirstTestDate,vDataSource,vAveUnavailability,
vFrequency,vFailureRate,vMTTR,vTestInterval,
vMissionTime,vDescription;
pRecordset.CreateInstance("ADODB.Recordset");
pRecordset->Open(_variant_t(list),
_variant_t((IDispatch*)pmain->m_pConnection, true),
adOpenStatic, adLockOptimistic, adCmdText);
int nCount = pRecordset->RecordCount;
vComponentType = pRecordset->GetCollect("部件类型");
vCode = pRecordset->GetCollect("编码");
vSummary = pRecordset->GetCollect("综述");
vOperatingMode = pRecordset->GetCollect("运行模式");
vOperatingEnvironment = pRecordset->GetCollect("运行环境");
vFailureDistribution = pRecordset->GetCollect("失效分布");
vFailureRate = pRecordset->GetCollect("失效率");
vFM = pRecordset->GetCollect("失效模式");
vDataSource = pRecordset->GetCollect("来源");
vAveUnavailability = pRecordset->GetCollect("平均不可用度");
vFrequency = pRecordset->GetCollect("发生频率");
vMTTR = pRecordset->GetCollect("平均维修时间");
vDescription = pRecordset->GetCollect("说明");
vMissionTime = pRecordset->GetCollect("任务时间");
vTestInterval = pRecordset->GetCollect("试验间隔");
//vReliabilityModel = pRecordset->GetCollect("可靠性模型");
//vComponentBoundary = pRecordset->GetCollect("部件边界");
//vFirstTestDate = pRecordset->GetCollect("第一次试验时间");
pRecordset->Close();
CString list3("SELECT * FROM [");
CString list4("]..[");
CString list5("]");
list3 = list3 + pApp->m_DBName+ list4 +pApp->m_DBName+list5;
pRecordset1.CreateInstance( "ADODB.Recordset" );
//打开目的数据库中的表。//
pRecordset1->Open(_variant_t(list3),
_variant_t((IDispatch*)pmain->m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
//粘贴记录。//
pRecordset1->AddNew( );
pRecordset1->PutCollect( "来源", _variant_t( vDataSource ) );
pRecordset1->PutCollect( "平均不可用度", _variant_t( vAveUnavailability ) );
pRecordset1->PutCollect( "部件边界", _variant_t( vComponentBoundary ) );
pRecordset1->PutCollect( "部件类型", _variant_t( vComponentType ) );
pRecordset1->PutCollect( "说明", _variant_t( vDescription ) );
pRecordset1->PutCollect( "失效分布", _variant_t( vFailureDistribution ) );
pRecordset1->PutCollect( "失效率", _variant_t( vFailureRate ) );
//pRecordset1->PutCollect( "第一次试验时间", _variant_t( vFirstTestDate ) );
pRecordset1->PutCollect( "失效模式", _variant_t( vFM ) );
pRecordset1->PutCollect( "发生频率", _variant_t( vFrequency ) );
pRecordset1->PutCollect( "任务时间", _variant_t( vMissionTime ) );
pRecordset1->PutCollect( "平均维修时间", _variant_t( vMTTR ) );
pRecordset1->PutCollect( "运行环境", _variant_t( vOperatingEnvironment ) );
pRecordset1->PutCollect( "运行模式", _variant_t( vOperatingMode ) );
pRecordset1->PutCollect( "可靠性模型", _variant_t( vReliabilityModel ) );
pRecordset1->PutCollect( "综述", _variant_t( vSummary ) );
pRecordset1->PutCollect( "试验间隔", _variant_t( vTestInterval ) );
pRecordset1->PutCollect( "编码", _variant_t( vCode ) );
///把新纪录保存到数据库中。///
pRecordset1->Update();
int nItem;
nItem=m_conData.InsertItem(0,(_bstr_t)vCode);
m_conData.SetItem(0,1,LVIF_TEXT,(_bstr_t)vComponentType,NULL,0,0,0);
m_conData.SetItem(0,2,LVIF_TEXT,(_bstr_t)vSummary,NULL,0,0,0);
UpdateData(FALSE);
pRecordset1->Close();
}
AfxMessageBox("记录已经复制完成!");
}
catch(_com_error &e )///捕捉异常
{
AfxMessageBox(e.Description());
}
pApp->CodeArray.RemoveAll();
}
我用这个类实现从源数据库pApp->m_CopyDB 到目标数据库pApp->m_DBName的记录复制,可是如果粘贴一次可以,粘贴第二次就会出错,请问如果解决!
2 个解决方案
#1
up
#2
第二次粘贴时需要与第一粘贴时一样,完成正确的初始化(正确的赋值,还有在操作过程中,操作库的权限的等变化也会到致再次操作失败)。
#1
up
#2
第二次粘贴时需要与第一粘贴时一样,完成正确的初始化(正确的赋值,还有在操作过程中,操作库的权限的等变化也会到致再次操作失败)。