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. Database & SysAdmin
  3. Database
  4. Can I retrieve column names using MFC classes

Can I retrieve column names using MFC classes

Scheduled Pinned Locked Moved Database
c++question
5 Posts 3 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.
  • C Offline
    C Offline
    Charles Liu
    wrote on last edited by
    #1

    I am developing a MFC-based program (using CRecordset and CDatabase) dealt with MS Access. I want to retrieve the column names of a table. Could I do that without using ODBC APIs?

    D T 2 Replies Last reply
    0
    • C Charles Liu

      I am developing a MFC-based program (using CRecordset and CDatabase) dealt with MS Access. I want to retrieve the column names of a table. Could I do that without using ODBC APIs?

      D Offline
      D Offline
      DiWa
      wrote on last edited by
      #2

      As far as I know, there is no way to get the column names with CRecordset or CDatabase. You can only use the m_hdbc member to feed it in the SQLGet**** - functions.

      1 Reply Last reply
      0
      • C Charles Liu

        I am developing a MFC-based program (using CRecordset and CDatabase) dealt with MS Access. I want to retrieve the column names of a table. Could I do that without using ODBC APIs?

        T Offline
        T Offline
        tomiczek
        wrote on last edited by
        #3

        You can use member GetODBCFieldInfo of CRecordset: void GetODBCFieldInfo( short nIndex, CODBCFieldInfo& fieldinfo ); // Definition of CODBCFieldInfo struct CODBCFieldInfo { CString m_strName; //thats what you want SWORD m_nSQLType; UDWORD m_nPrecision; SWORD m_nScale; SWORD m_nNullability; };

        C 1 Reply Last reply
        0
        • T tomiczek

          You can use member GetODBCFieldInfo of CRecordset: void GetODBCFieldInfo( short nIndex, CODBCFieldInfo& fieldinfo ); // Definition of CODBCFieldInfo struct CODBCFieldInfo { CString m_strName; //thats what you want SWORD m_nSQLType; UDWORD m_nPrecision; SWORD m_nScale; SWORD m_nNullability; };

          C Offline
          C Offline
          Charles Liu
          wrote on last edited by
          #4

          Sorry,I found that I hadn't expressed myself clearly. What I want to know is all the column names of the table, not only the names in the recordset.

          D 1 Reply Last reply
          0
          • C Charles Liu

            Sorry,I found that I hadn't expressed myself clearly. What I want to know is all the column names of the table, not only the names in the recordset.

            D Offline
            D Offline
            DiWa
            wrote on last edited by
            #5

            I think you got to do it this way (in pseudocode): SQLExecDirect( "Select * from ") SQLNumResultCols(); for( i < NumResultCols ) { SQLDescribeCol( i ) } that should do the trick. dirk

            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