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;
    }

  • 相关阅读:
    8.24
    8.23
    今日拔牙牙疼暂时不评论了,明天展示的时候老师也会给出建议
    8.22
    8.21
    8.20
    8.19随笔
    助教培训第四次作业
    助教培训第三次作业-墨刀的练习
    同时安装多个jdk设置及切换
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/1806567.html
Copyright © 2011-2022 走看看