Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A CRecordset Problem.

A CRecordset Problem.

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    willyfu
    wrote on last edited by
    #1

    I use Teradata database. Teradata has a SQL Statement :show table mytable; This statement can return the definition of mytable. But CRecordset class cann't run this SQL. CDatabase can do it,but CDatabase.ExecuteSQL function has no return . strSQL = "Show table mytable;"; set.Open(CRecordset::forwardOnly,(LPCTSTR)strSQL,CRecordset::none);//Error ! database.ExecuteSQL(strSQL);//OK,but how can I get the result? How can I run this SQL and get the result? Thanks.

    D 1 Reply Last reply
    0
    • W willyfu

      I use Teradata database. Teradata has a SQL Statement :show table mytable; This statement can return the definition of mytable. But CRecordset class cann't run this SQL. CDatabase can do it,but CDatabase.ExecuteSQL function has no return . strSQL = "Show table mytable;"; set.Open(CRecordset::forwardOnly,(LPCTSTR)strSQL,CRecordset::none);//Error ! database.ExecuteSQL(strSQL);//OK,but how can I get the result? How can I run this SQL and get the result? Thanks.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      willyfu wrote: How can I run this SQL and get the result? Getting the results from a stored procedure is not that difficult. One way of doing it is shown in MSDN article Q183001. Here is another. Here is a helpful discussion.


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      W 1 Reply Last reply
      0
      • D David Crow

        willyfu wrote: How can I run this SQL and get the result? Getting the results from a stored procedure is not that difficult. One way of doing it is shown in MSDN article Q183001. Here is another. Here is a helpful discussion.


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        W Offline
        W Offline
        willyfu
        wrote on last edited by
        #3

        finally,I found the ODBC API solution. CString strSQL; SQLLEN nRecCount,nFieldLen; strSQL.Format("Show table mytable;"); CRecordset set(&database);//Create a CRecordset object SQLExecDirect(set.m_hstmt,(SQLCHAR*)strSQL.GetBuffer(strSQL.GetLength()),strSQL.GetLength()); SQLRowCount(set.m_hstmt,&nRecCount); for(int n = 0;n < nRecCount; n++) { SQLFetch(set.m_hstmt); SQLGetData(set.m_hstmt,1,1,str1.GetBuffer(32000),32000,&nFieldLen); str1.ReleaseBuffer(); } that's all.

        D 1 Reply Last reply
        0
        • W willyfu

          finally,I found the ODBC API solution. CString strSQL; SQLLEN nRecCount,nFieldLen; strSQL.Format("Show table mytable;"); CRecordset set(&database);//Create a CRecordset object SQLExecDirect(set.m_hstmt,(SQLCHAR*)strSQL.GetBuffer(strSQL.GetLength()),strSQL.GetLength()); SQLRowCount(set.m_hstmt,&nRecCount); for(int n = 0;n < nRecCount; n++) { SQLFetch(set.m_hstmt); SQLGetData(set.m_hstmt,1,1,str1.GetBuffer(32000),32000,&nFieldLen); str1.ReleaseBuffer(); } that's all.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          While it may work, this is a very odd use of a CString object. I'm curious why you are using a CRecordset object if all you need access to is its m_hstmt member.


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups