zoukankan      html  css  js  c++  java
  • VC中ADO

    1,StdAfx.h中加入
    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")
    2,
    BOOL C***App::InitInstance()
    {
     AfxEnableControlContainer();

     if(!AfxOleInit()) 
     {
      AfxMessageBox("OLE初始化Error");
      return FALSE;
     }

     if (FAILED(pConn.CreateInstance("ADODB.Connection")))
     {
      AfxMessageBox("Create Instance failed!");
      return FALSE;
     }

     CString strSRC = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\Test.mdb;Jet OLEDB:Database Password=80";

     _bstr_t bstrSRC(strSRC);
     if (FAILED(pConn->Open(bstrSRC,"","",-1)))
     {
      AfxMessageBox("Can not open Database!");
      pConn.Release();
      return FALSE;
     }
    ......
    }

    void C***Dlg::AccessSql(CString szSql)
    {
     _bstr_t bstrSql( szSql );
     pCommand.CreateInstance(__uuidof(Command));
     pCommand->ActiveConnection = pConn;
     pCommand->CommandText = bstrSql;
     pCommand->CommandType = adCmdText;
     pCommand->Parameters->Refresh();
     pRs = pCommand->Execute(NULL,NULL,adCmdUnknown);
    }

    CString C***Dlg::GetStrValue(CString szSql, CString szFeild)
    {
     _bstr_t bstrFeild( szFeild );
     AccessSql( szSql );
     if( pRs->adoEOF )
      return "";
     _variant_t varValue = pRs->GetCollect( bstrFeild );
     CString Value = (char*)_bstr_t(varValue);
     return Value;
    }

    double C***Dlg::GetDoubleValue(CString szSql, CString szFeild)
    {
     _bstr_t bstrFeild( szFeild );
     AccessSql( szSql );
     if( pRs->adoEOF )
      return -1;
     _variant_t varValue = pRs->GetCollect( bstrFeild );
     double Value = (double)varValue;
     return Value;
    }

    long C***Dlg::GetIntValue(CString szSql, CString szFeild)
    {
     _bstr_t bstrFeild( szFeild );
     AccessSql( szSql );
     if( pRs->adoEOF )
      return -1;
     _variant_t varValue = pRs->GetCollect( bstrFeild );
     long Value = (long)varValue;
     return Value;
    }

  • 相关阅读:
    <td>标签clospan和rowspan 可横跨列数和行数
    网线水晶头接法
    安装在墙上的网线接口坏了的处理方法
    php array 数组及数组索引
    php strpos返回字符串首次出现的位置
    escape()、encodeURI()、encodeURIComponent()区别详解
    smarty assign 赋值
    二叉搜索树(搜索二叉树)转换成一个双向链表
    new malloc和delete free 的区别
    两个栈实现一个队列
  • 原文地址:https://www.cnblogs.com/SharkXu/p/708348.html
Copyright © 2011-2022 走看看