如何把用ado的CRecordSet记录集导出的XML,存回到原来的表中? 如题/ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 pRstAuthors->Open("SELECT * FROM Authors",strCnn, adOpenDynamic,adLockOptimistic,adCmdText); pRstAuthors->Save("a:\\Pubs.xml",adPersistXML);-------------------------------------------------------- pRstAuthors->Open("a:\\Pubs.xml","Provider=MSPersist;", adOpenForwardOnly,adLockOptimistic,adCmdFile); lz可以查阅这里 "C:\Program Files\Common Files\Microsoft Shared\Office10\2052\ADO210.CHM"搜索save,看例子就行了 pRstAuthors-> Open("a:\\Pubs.xml","Provider=MSPersist;", adOpenForwardOnly,adLockOptimistic,adCmdFile); 这个函数是把XML文件中的数据导入了记录集,没有存到表里面吧? pRstAuthors->PutActiveConnection(_variant_t((IDispatch *) pCnn)); pRstAuthors->UpdateBatch(adAffectAll);这个是我刚才所说的那个文件里的范例,里面有如何把它再存进表里 CString sPath="c:\\test.xml";_bstr_t strCnn("Provider='sqloledb';Data Source=(local);" "Initial Catalog='testdb';Integrated Security='SSPI';");try{ _ConnectionPtr pCon;HRESULT hr=pCon.CreateInstance(__uuidof(Connection)); hr=pCon->Open(strCnn,"","",NULL);_RecordsetPtr pRst;pRst.CreateInstance(__uuidof(Recordset));pCon->BeginTrans();pRst-> Open((LPCTSTR)sPath,"Provider='MSPersist'",adOpenKeyset,adLockBatchOptimistic,adCmdFile); pRst->PutActiveConnection(_variant_t((IDispatch *)pCon));hr =pRst->UpdateBatch(adAffectAll); if(SUCCEEDED(hr)) pCon->CommitTrans(); else {MessageBox(sPath,"错误",MB_ICONERROR); }pRst->Close();pCon->Close();}catch(_com_error &e){ MessageBox("错误");} 单步调试,到pRst-> UpdateBatch(adAffectAll);一直最后都没问题 按照ado2.5帮助中的例子实现了一遍,发现如下问题: (1)由UpdateBatch()函数只能更新,而不能插入, (2)更新数据库的时候打开的文件为adtg文件,而不是导出的xml文件, 这样想实现把XML文件存回到一个空的表中,肯定是不行的. 例子的作用只是更新,而不是生成 BCG对话框OnEnChangeEdit的奇怪问题 技术分很重要吗?回答问题仅仅为了技术分吗? 对话框关闭问题 关于打开帮助文件(CHM). 诚聘C++软件工程师 win32平台如何调用16位的DLL? 加班调查~ 急!怎么能在RichEdit中写文字和插入图片,就像QQ一样 静态函数定义的变量是静态的吗? 请教文件操作高手!!(100分) 如何把一个打开的记录集存回到另一个表中去? 如何获得WAV文件的倍速,然后对其进行修改,,
adOpenDynamic,adLockOptimistic,adCmdText);
pRstAuthors->Save("a:\\Pubs.xml",adPersistXML);
--------------------------------------------------------
pRstAuthors->Open("a:\\Pubs.xml","Provider=MSPersist;",
adOpenForwardOnly,adLockOptimistic,adCmdFile);
搜索save,看例子就行了
adOpenForwardOnly,adLockOptimistic,adCmdFile);
这个函数是把XML文件中的数据导入了记录集,没有存到表里面吧?
pRstAuthors->UpdateBatch(adAffectAll);
这个是我刚才所说的那个文件里的范例,里面有如何把它再存进表里
_bstr_t strCnn("Provider='sqloledb';Data Source=(local);"
"Initial Catalog='testdb';Integrated Security='SSPI';");try
{
_ConnectionPtr pCon;
HRESULT hr=pCon.CreateInstance(__uuidof(Connection));
hr=pCon->Open(strCnn,"","",NULL);_RecordsetPtr pRst;
pRst.CreateInstance(__uuidof(Recordset));
pCon->BeginTrans();
pRst-> Open((LPCTSTR)sPath,"Provider='MSPersist'",adOpenKeyset,adLockBatchOptimistic,adCmdFile);
pRst->PutActiveConnection(_variant_t((IDispatch *)pCon));
hr =pRst->UpdateBatch(adAffectAll);
if(SUCCEEDED(hr))
pCon->CommitTrans();
else
{MessageBox(sPath,"错误",MB_ICONERROR);
}
pRst->Close();
pCon->Close();
}
catch(_com_error &e)
{
MessageBox("错误");
}
(1)由UpdateBatch()函数只能更新,而不能插入,
(2)更新数据库的时候打开的文件为adtg文件,而不是导出的xml文件,
这样想实现把XML文件存回到一个空的表中,肯定是不行的.
例子的作用只是更新,而不是生成