目前刚接触这些东西,憋得脑袋都大了。 ~~~导师都下催命书了...T_T
描述:两台服务器,一台是SQL,一台是DB2,把SQL中的一个表的数据导入DB2中已经建好的一张表中。我建了两个数据库类,一个是CSQL,一个是CDB2。
CDB2类代码:
void CDB2::OnInitDB2Conn()
{
::CoInitialize(NULL);
m_pConnection.CreateInstance(__uuidof(Connection));
_bstr_t strConn = "Provider=IBMDADB2.DB2COPY1;Persist Security Info=False;User ID=db2admin;Data Source=BSMPWS1;Location="";Extended Properties=""";
m_pConnection->Open(strConn,"db2admin","db2admin",adModeUnknown);
}
_RecordsetPtr & CDB2::GetRecordSet(_bstr_t strSQL)
{
if(m_pConnection == NULL)
OnInitDB2Conn();
m_pRecordset.CreateInstance(__uuidof(Recordset)); //初始化Recordset指针
m_pRecordset->Open(strSQL,m_pConnection.GetInterfacePtr(), adOpenDynamic,adLockOptimistic,adCmdText);
return m_pRecordset;
}
BOOL CDB2::ExecuteSQL(_bstr_t strSQL)
{
_variant_t RecordsAffected;
if(m_pConnection==NULL)
OnInitDB2Conn();
m_pConnection->Execute(strSQL,NULL,adCmdText);
return true;
}
CSQL类同上
Dlg类中导数据部分:
void CDatabaseDlg::OnBtnCopy()
{
CSQL sqlCopy;
sqlCopy.OnInitSQLConn();
CDB2 db2Copy;
db2Copy.OnInitDB2Conn();
_bstr_t DB2_delete = "delete * from bs_info_gather"; //清空DB2数据库表中的数据
db2Copy.ExecuteSQL(DB2_delete);
_bstr_t SQL_AGENCY = "select * from bs_agency";
_RecordsetPtr agency_pRecordset;
agency_pRecordset = sqlCopy.GetRecordSet(SQL_AGENCY); //打开并获取SQL的bs_agency记录集
_bstr_t DB2_AGENCY = "select * from bs_info_gather";
_RecordsetPtr db2_pRecordset;
db2_pRecordset = db2Copy.GetRecordSet(DB2_AGENCY); //打开并获取DB2数据集
try
{
while(agency_pRecordset->adoEOF==0)
{
db2_pRecordset->AddNew(); ##############################1
//将SQL中AGENCY_TITLE字段数据传到DB2中BS_TITLE里
_bstr_t an1 = agency_pRecordset->GetCollect("AGENCY_TITLE");
db2_pRecordset->PutCollect("BS_TITLE",an1);
_bstr_t an2 = agency_pRecordset->GetCollect("AGENCY_CONTENT");
db2_pRecordset->PutCollect("BS_CONTENT",an2);
... ...
db2_pRecordset->MoveNext();
}
db2_pRecordset->Update();
}
.....
}
调试时在########1处抛出“当前记录集不支持更新。这可能是提供程序的限制,也可能是选定锁定类型的限制。”麻烦帮我分析分析哪里出问题了。