• c++builder 6.0 使用ado


    可以使用系统的TADOConnection 组件,这里使用原生对象来操作,只用于学习

    1.导入ado库 import library ,生成adodb_ocx.h,adodb_tlb.h

    2.修改生成的头文件,

    1. String sql_update = "update userinfo set name = 'abc'";
    2. TConnection* db = new TConnection(this);
    3. int iState =0 ;
    4. try
    5. {
    6. try
    7. {
    8. db->ConnectionString = UTF8Decode("Provider=SQLOLEDB.1;Password=000000;Persist Security Info=True;User ID=sa;Initial Catalog=TEST;Data Source=127.0.0.1");
    9. db->Open(NULL,NULL,NULL,adConnectUnspecified);
    10. if(db->State != adStateOpen) ;
    11. {
    12. if(db->Errors->Count >0)
    13. {
    14. Variant i = 0 ;
    15. String str = db->Errors->get_Item(i)->Description ;
    16. MessageBox(Handle,str.c_str(),"error",MB_ICONSTOP);
    17. }
    18. return ;
    19. }
    20. Variant iRows = -1;
    21. db->Execute(UTF8Decode(sql_update),iRows,adCmdText);
    22. Edit1->Text = IntToStr(iRows.lVal);
    23. }
    24. catch(Exception& e )
    25. {
    26. if(db->Errors->Count >0)
    27. {
    28. Variant i = 0 ;
    29. String str = db->Errors->get_Item(i)->Description ;
    30. MessageBox(Handle,str.c_str(),"error",MB_ICONSTOP);
    31. }
    32. }
    33. }
    34. __finally
    35. {
    36. db->Close();
    37. delete db ;
    38. }

    遇到的错误:

    1.函数调用,没用任何反应:

    修改h文件中的声明

     __property BSTR ConnectionString={ read=get_ConnectionString,write = set_ConnectionString, stored=false};

     stored=false 改为stored=true

    2.com异常提示框 "HRCHECK"

    #if !defined(OLECHECK)
    #define OLECHECK(hrexpr) DebugHlpr_HRCHECK(hrexpr, #hrexpr, __FILE__, __LINE__)
    #endif

    void DebugHlpr_THROW(T* msg, HRESULT hr, T* file, bool /*assertFailed*/)
    {
    #if defined(ComObjHPP)
      // NOTE: This does not retrieve rich error information, the way Delphi and VB environments
      //       do. Eventually this 'throw' will either throw a rich EOleException or some other
      //       OLE exception class (something equivalent to _com_error, maybe??)
      //
      //       For now, you can specialized [T = TCHAR] 'DebugHlpr_THROW' to retrieve rich error
      //       information and throw a VCL exception class, if you're using VCL classes already,
      //       or throw a custom exception class.
      //
      //       NOTE: Use the assertFailed parameter to distinguish between Assertion and
      //             OLECHECK failures. (Maybe throw something different??)
      throw EOleException(msg, hr, file, _T(""), 0);
    #else
      throw msg;  // Hopefully we never get here: Need something much better to throw!!
    #endif
    }

    处理:#define OLECHECK 1,默认是检查OLE异常


    #if !defined(PROMPT_ON_HRCHECK_FAILURE)
        int i = IDYES;
    #else
        int i = DebugHlpr_PROMPT(_T("HRCHECK: "), szMsg);
    #endif
        if (i == IDYES)
          DebugHlpr_THROW(szMsg, hr,lfile, false);
        else if (i == IDCANCEL)
          ::DebugBreak();
        // NOTE: IDNO - implies we keep chugging along
      }

    处理:#define PROMPT_ON_HRCHECK_FAILURE 1   ,就不会在运行时报HRCHECK提示框

  • 相关阅读:
    vue 时间戳转日期格式
    206.反转链表
    shell脚本:if语句
    使用git-repo管理多个git仓库
    Kubernetes 集群部署 Prometheus 和 Grafana
    maven build An unknown compilation problem occurred
    Spectacle/Flameshot/X11 Xlib截屏问题现象及解决方法
    Red Hat Enterprise Linux RHEL 8.6 下载安装
    @Async异步失效的9种场景
    网络安全(黑客)-小白自学
  • 原文地址:https://blog.csdn.net/aasmfox/article/details/84438581