• 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提示框

  • 相关阅读:
    Hashtable为什么效率很低
    Java自动化测试框架有哪几类、区别是什么?
    Windows Nginx 服务器部署(保姆级)
    csgo搬砖详细讲解,月入破万长期稳定
    LNMP网站架构部署
    Kotlin与Java写法的变更
    谷歌开源的LLM大模型 Gemma 简介
    LeetCode 每日一题 2023/9/11-2023/9/17
    C#用API读取.ini非中英文路径失败问题
    【Vue】Vuex详解,一文读懂并使用Vuex
  • 原文地址:https://blog.csdn.net/aasmfox/article/details/84438581