下载此文档

C 编程常用模块.doc


文档分类:IT计算机 | 页数:约82页 举报非法文档有奖
1/82
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/82 下载此文档
文档列表 文档介绍
1(一):连接SQL数据库一、连接数据库(SQL):(一)直接写在程序中1、导入动态连接库:#import"C:\monFiles\System\ado\"no_namespace\rename("EOF","adoEOF")rename("BOF","adoBOF")2、定义Provider宏:#defineProvider"Provider=;IntegratedSecurity=SSPI;\PersistSecurityInfo=False;InitialCatalog=HRMS"3、初始化a).h文件中private:HDCm_hDC;DWORDm_CurrentRecord;_RecordsetPtrm_pRecordset;_ConnectionPtrm_pConnection;b).cpp文件中CADOOperation::CADOOperation(){try{(_uuidof(Connection));m_pConnection->Open(_bstr_t(Provider),"","",adModeUnknown);}catch(_com_errore){AfxMessageBox((),MB_OK);exit(0);}(_uuidof(Recordset));m_CurrentRecord=-1;}4、执行5、关闭CADOOperation::~CADOOperation(){m_pConnection->Close();}(二)voidCBbbApp::IniAdo(){try{CStringtemp;charfilepath[MAX_PATH];GetModuleFileName(NULL,filepath,MAX_PATH);temp=(filepath);//获取可执行文件的路径,//运行后,所在路径CStringstrAdoConn;chartemp1[100];/*********************************************,并在其中设置数据库连接字符串,如:[DatabaseConfig]Server=.//.表示本机Database=BookManageUser=saPWD=sa*********************************************/GetPrivateProfileString("DatabaseConfig","Server","",temp1,100,temp+"");strserver=(TCHAR*)temp1;GetPrivateProfileString("DatabaseConfig","Database","",temp1,100,temp+"");strdbName=temp1;GetPrivateProfileString("DatabaseConfig","User","",temp1,100,temp+"");strUser=temp1;GetPrivateProfileString("DatabaseConfig","PWD","",temp1,100,temp+"");strPassword=temp1;("driver={SQLServer};SERVER=%s;UID=%s;PWD=%s;DATABASE=%s",strserver,strUser,strPassword,strdbName);(_uuidof(Connection));m_pCon->ConnectionString=(_bstr_t)strAdoConn;m_pCon->Open("","","",NULL);("");(_uuidof(Recordset));(_uuidof(Recordset));//ADOFLAG=TRUE;}catch(_com_error){//ADOFLAG=FALSE;Flag=FALSE;MessageBox(0,"请检查系统配置信息","数据库连接失败",MB_OK);return;}catch(...){AfxMessageBox("SYSError");return;}}C++编程常用模块(二):ess数据库二、连接数据库(Access)1、#import"C:\monFiles\System\ado\"no_namespace\rename("EOF","adoEOF")rename("BOF","adoBOF")类定义:classADOConn{public:BOOLExecuteSQL(_bstr_tbstrSQL);ADOConn();virtual~ADOConn();//添加一个指向Connection对象的指针_ConnectionPtrm_pConnection;//

C 编程常用模块 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息