欢迎来到天天文库
浏览记录
ID:14382977
大小:58.00 KB
页数:21页
时间:2018-07-28
《mfc数据库操作大全》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MFC数据库操作大全1.提取单条记录/*#import"c:ProgramFilesCommonFilesSystemADOmsado15.dll"o_namespacerename("EOF","EndOfFile")*/CoInitialize(NULL);_bstr_tvarSource="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%%0";//*.mdb//_bstr_tvarSource="DataSource=127.0.0.1;Initial
2、Catalog=db2;UserId=;Password=;"_ConnectionPtrm_pConnection(_uuidof(Connection));m_pConnection->Open(varSource,"","",adModeUnknow);_RecordsetPtrm_pSet(_uuidof(Recordset));try{m_pSet->Open(%%1,m_pConnection.GetInterfacePtr()adOpenDynamic,adLockPessimistic,adCmdT
3、ext);}catch(_com_error*e){{AfxMessageBox(e->ErrorMessage());return;}_variant_tvar;CString%%2="";longfldc=m_pSet->GetFields()->GetCount();longi=0;try{m_pSet->MoveFirst();if(!m_pSet->adoEOF){for(i=0;iGetCollect((long)i);var.ChangeType(VT_B
4、STR);%%2+=var.bstrVal;%%2+="";}//m_pSet->MoveNext();}}catch(_com_error*e){AfxMessageBox(e->ErrorMessage());deletee;}//m_pSet->MoveFirst();CoUninitialize();2.单值比较/*#import"c:ProgramFilesCommonFilesSystemADOmsado15.dll"o_namespacerename("EOF","EndOfFile")
5、*/CoInitialize(NULL);_bstr_tvarSource="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%%0";//*.mdb//_bstr_tvarSource="DataSource=127.0.0.1;InitialCatalog=db2;UserId=;Password=;"_ConnectionPtrm_pConnection(_uuidof(Connection));m_pConnection->Open(varSource,"","",a
6、dModeUnknown);_RecordsetPtrm_pSet(_uuidof(Recordset));try{m_pSet->Open(%%1,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);}catch(_com_error*e){{AfxMessageBox(e->ErrorMessage());return;}_variant_tvar;try{m_pSet->MoveFirst();if(!m_pSe
7、t->adoEOF){var=m_pSet->GetCollect((long)0);var.ChangeType(VT_I2);int%%3=var.intVal;if(%%3==%%4){%%5}//m_pSet->MoveNext();}catch(_com_error*e){AfxMessageBox(e->ErrorMessage());deletee;}//m_pSet->MoveFirst();CoUninitialize();3.显示表格/*#import"c:ProgramFilesCommo
8、nFilesSystemADOmsado15.dll"o_namespacerename("EOF","EndOfFile")*/CoInitialize(NULL);_bstr_tvarSource="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%%0";//*.mdb//_bstr_tvarSourc
此文档下载收益归作者所有