• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
平衡适可而止
博客园    首页    新随笔    联系   管理    订阅  订阅

帮忙调试下这个程序 谢谢。。。

//运行环境 VS2005 数据库 sql2000

// DAO.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
  #include   <string>  
  #include   <iostream>  
  using   namespace   std;  
  #import   "C:\Program Files\Common Files\System\ado\msado15.dll"   no_namespace   rename("EOF","adoEOF")  
   
   
  int   main(int   argc,   char*   argv[])  
  {  
        _ConnectionPtr   pConn=NULL;  
        _RecordsetPtr   pRss=NULL;  
        _variant_t   i_code;  
        _variant_t   beg_date;  
        _variant_t   end_date;  
        _variant_t   sw_total_stock;  
        _variant_t   sw_publish_stock;  
        string   m_str_i_code;  
        string   m_str_beg_date;  
        string   m_str_end_date;  
        string   m_str_total_stock;  
        string   m_str_publish_stock;  
        _bstr_t   strConn,strSQL;  
        HRESULT   hr;          
   
        ::CoInitialize(NULL);  
       
        try  
        {  
   strConn="Provider=SQLOLEDB;Server=(local);DATABASE=Northwind;UID=sa;PWD=";  
   strSQL="select * from Products";  
   
   hr=pConn.CreateInstance(__uuidof(Connection));  
   if(SUCCEEDED(hr))  
   {        
    if(pConn->GetState()==adStateClosed)  
    {  
     pConn->Open(strConn,"","",adModeUnknown);  
    }  
    pRss.CreateInstance(__uuidof(Recordset));  
    if(pRss->GetState()==adStateClosed)  
    pRss->Open(strSQL,pConn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);  
                 
    while(!pRss->adoEOF)  
    {  
     i_code=pRss->GetCollect("ProductName");  

     m_str_i_code=(string)(char*)(_bstr_t)i_code;  

     cout<<m_str_i_code<<endl;  
     pRss->MoveNext();  
     
    }  
   }  
           
         
        }  
        catch(_com_error*   e)  
        {  
            cout<<e->ErrorMessage()<<endl;  
            cout<<"数据库连接失败,请检查错误!";  
        }  
      try  
      {  
        pRss->Close();  
        pRss=NULL;  
        //pRss->Release();  
        pConn->Close();  
        pConn=NULL;  
        //pConn->Release();  
        ::CoUninitialize();  
      }  
      catch(_com_error   &e)  
      {  
          cout<<e.ErrorMessage()<<endl;  
      }  
   
        return   0;  
  }  

posted @ 2010-01-24 16:44  平衡适可而止  阅读(141)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3