VC程序中生成了数据库文件;(基于对话框的小程序,)现在想增加打印功能,打算使用
XML格式并显示,
问题是:
1)不知道在VC中如何实现将数据库转换为XML文件。
2)在VC程序中如何调用生成好的XML(XSL)文件。
XML格式并显示,
问题是:
1)不知道在VC中如何实现将数据库转换为XML文件。
2)在VC程序中如何调用生成好的XML(XSL)文件。
解决方案 »
- OpenGL 三维地层建模
- 新手提问-关于COM实现中的宏
- (急)ruby 调用vc写的库文件问题
- 为什么CStatusBar在OnInitDialog类使用指针声明会出现exe终止运行
- 100分求使用API取IE的所在目录(除注册表方法外)?
- 如何使进程不能被任务管理器关掉或被命令行杀死?
- 一本《深入潜出MFC》出售,4折,有要买的吗,在北京,自取!
- 请教一下大家,假如想当鼠标放在树型结点上的时候出现一段文字,该用什么函数啊
- 请教:关于用VC做的DLL,delphi如何使用的问题(初级)
- libnids 捕获不了HTTP客户端信息
- 见笑!! 关于使用ADO的智能指针_RecordsetPtr作为函数的参数变量进行调用的问题?
- 能介绍一下在窗口中对位图进行拖放的原理吗?有源码更好.谢谢!高分相送!!
2。用msxml解析
{
if(!UpdateData())return; CString strSQL,strTimeField,strTableName,strXMLFile,strStylesheet; switch(m_iReportType){
case 0:
strTableName="Rockey";
strTimeField="LastWriteDate";
break;
case 1:
strTableName="RockeyWrite";
strTimeField="WriteDate";
break;
}
strSQL.Format("Select * From %sReport",strTableName);
strXMLFile.Format("%s.xml",strTableName);
strStylesheet.Format("type='text/xsl' href='%s.xsl'",strTableName);
CString strFilter;
COleDateTime dtFrom=COleDateTime::GetCurrentTime();
int nDateDiff=0;
switch(m_iPeriod){
case 0:nDateDiff=1;break;
case 1:nDateDiff=7;break;
case 2:nDateDiff=15;break;
case 3:nDateDiff=30;break;
case 4:nDateDiff=60;break;
case 5:break;
}
dtFrom-=COleDateTimeSpan(nDateDiff,0,0,0);
if(m_iPeriod!=5){
strFilter.Format("%s>=#%s#",strTimeField,dtFrom.Format());
}
try{
MSXML2::IXMLDOMDocument2Ptr pDoc("Msxml2.DOMDocument.4.0");
ado20::_RecordsetPtr pset("ADODB.Recordset");
MSXML2::IXMLDOMProcessingInstructionPtr pProcessingInstruction;
MSXML2::IXMLDOMElementPtr pElement;
MSXML2::IXMLDOMElementPtr pRoot;
ado20::FieldsPtr pFields;
pset->Open((LPCTSTR)strSQL,_variant_t((IDispatch *)theApp.m_pConnection,true) ,adOpenDynamic,adLockOptimistic,adCmdUnspecified); pset->Filter=(LPCTSTR)strFilter;
int nFieldCount=pset->Fields->Count;
pProcessingInstruction=pDoc->createProcessingInstruction("xml",
"version='1.0' encoding='gb2312'");
pDoc->appendChild(pProcessingInstruction);
pProcessingInstruction=pDoc->createProcessingInstruction("xml-stylesheet",
(LPCTSTR)strStylesheet);
pDoc->appendChild(pProcessingInstruction);
pRoot=pDoc->createElement("Data");
pDoc->appendChild(pRoot);
pFields=pset->Fields;
while(pset->EndOfFile==VARIANT_FALSE){
pElement=pDoc->createElement("Row");
for(long i=0;i<nFieldCount;i++){
if(pFields->Item[i]->Value.vt!=VT_NULL)
pElement->setAttribute(pFields->Item[i]->Name,pFields->Item[i]->Value);
}
pRoot->appendChild(pElement);
pset->MoveNext();
}
pset->Close();
pDoc->save((LPCTSTR)strXMLFile);
}
catch(_com_error &e)
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError(theApp.m_pConnection);
PrintComError(e);
}
ShellExecute(NULL, NULL, strXMLFile, NULL, NULL, SW_SHOWNORMAL);
}
关于PrintProviderError和PrintComError的实现,参照XML4.0和ADO的SDK文档。