• c++针对数据库,文件的操作总结(原始)


    1.将文件保存到sqlserver数据库的相关操作:
      Update t1 set filedata = ‘.txt’ , filedata = ( select * from openrowset( bulk ‘E:1.txt’, SINGLE_BLOB ) as data ) where resultId = 5
      Select convert( varchar(8000), data ) from t1 where resultId = 2
      注:fileType: varchar(20), filedata: varbinary(MAX)
    2.将sqlserver里的文件数据读出来到文件:
      CFile outfile(...); // 参考MSDN
      LPSTR buffer = (LPSTR)GlobalLock( cdbvariant.m_pbinary->m_hData );
      Outfile.Write(buffer,cdbvariant.m_pbinary->m_dwDataLength);
      GlobalLock(cdbvariant.m_pbinary->m_hData);
      Outfile.close();
      
      执行某个文件:
      shellExecute( NULL,NULL,_T(“12.doc”), NULL,_T(“E:\12.doc”),NULL);
    3.文件查找:
      CFileFind findfile;
      CString path = “D:\”;
      If( path.Right(1) != “\”) path = path + “\*.bmp”;
      bool res = findfile.FindFile(path);
      While(res)
      {
        res = findfile.FindNextFile();
        if(!findfile.IsDots())
        {
          findfile.GetFileTitle();
          ....
        }
      }
    4.MFC显示图片
      HBITMAP hp;
      hp = (HBITMAP)LoadImage(NULL,_T(findfile.GetFilePath()),IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LRCREATEDIBSECTION);
      m_pictureshow.setBitmap(hp);
    5.得到当前的时间
      CTime ct = CTime::GetCurrentTime();
      CString nowTime = ct.Format(“%Y-%m-%d  %H:%M:%S”);
    6.连接数据库
      #include<afxdb.h>
      CDatabase cdb;
      if(!cdb.OpenEx( Getconnect(),CDatabase::noodbcDialog)){ return;}
      CRecordSet crs(&cdb);
      try
      {
        if( !crs.open( CRecordSet::dynamic, _T(“select * from t”)))
      { return ; }
      }catch( CDBException ee ){}
      short count = crs.GetODBCFiledCount();
      int row = 0;
      crs.MoveFirst();
      CDBVariant cdbvariant;
      while( !crs.IsEOF() )
      {
        int col =0;
        for( short index = 0; index < count; ++index)
        {
          crs.GetFileValue(index,cdbvariant);
          m_list.AddItem(row, ++col, ....);
        }
        ++row ;
        crs.MoveNext();
      }
      crs.close();
      cdb.close();
    7.打开word保存数据
      Colevariant, CApplication, CDocuments, CDocument0, CSelection
  • 相关阅读:
    A16 React+AntDesign AntDesignUI框架初识
    A15 React+AntDesign 路由模块化 嵌套路由父子组件传值
    A14 React+AntDesign 路由嵌套
    react中实现JavaScript跳转路由
    react打包 npm run build 出现空白页面
    在react中解析html标签代码
    es6 模板字符串 在字符串里写变量
    A13 React+AntDesign 路由配置 react-router5.1.2
    nginx动态配置,环境安装
    Spring配置文件内容加密
  • 原文地址:https://www.cnblogs.com/foreverstars/p/3321635.html
Copyright © 2020-2023  润新知