zoukankan      html  css  js  c++  java
  • VS2008C++利用ADO访问数据库

    stdafx.h中

    #pragma once

    #include "targetver.h"

    #include <stdio.h>
    #include <tchar.h>


    #import"C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")
    // TODO: reference additional headers your program requires here
    主程序中(以下代码修改自孙鑫VC++深入详解)

    代码
    #include "stdafx.h"
    #include
    <iostream>
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
        
    int end;
        CoInitialize(NULL);
        _ConnectionPtr pConn(__uuidof(Connection));
        _RecordsetPtr pRst(__uuidof(Recordset));
        pConn
    ->ConnectionString="Provider=SQLOLEDB.1;Password=finally;Persist Security Info=True; User ID=sa;Initial Catalog=pubs";
        pConn
    ->Open("","","",adConnectUnspecified);
        pRst
    =pConn->Execute("select * from authors",NULL,adCmdText);
        
    while(!pRst->rsEOF)
        {
            cout
    <<((_bstr_t)pRst->GetCollect("au_lname"))<<endl;;
            
            pRst
    ->MoveNext();
        }
        pRst
    ->Close();
        pConn
    ->Close();
        pRst.Release();
        pConn.Release();
        CoUninitialize();
        


        cin
    >>end;
        
    return 0;
    }

  • 相关阅读:
    poj 1860 Currency Exchange(最短路径的应用)
    poj 2965 The Pilots Brothers' refrigerator
    zoj 1827 the game of 31 (有限制的博弈论)
    poj 3295 Tautology (构造法)
    poj 1753 Flip Game(枚举)
    poj 2109 (贪心)
    poj 1328(贪心)
    Qt 对单个控件美化
    Qt 4基础
    Bash Shell
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/1806567.html
Copyright © 2011-2022 走看看