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. need help!!!!

need help!!!!

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelptutorialquestion
7 Posts 4 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.
  • B Offline
    B Offline
    bamboo
    wrote on last edited by
    #1

    Hi all the guru, I am currently using ODBC to access MS SQL. Can anybody tell me how to get number of columns if given table name? Thanks thanks thanks!!!:eek: vivi

    V B 2 Replies Last reply
    0
    • B bamboo

      Hi all the guru, I am currently using ODBC to access MS SQL. Can anybody tell me how to get number of columns if given table name? Thanks thanks thanks!!!:eek: vivi

      V Offline
      V Offline
      vikram attiganal
      wrote on last edited by
      #2

      Try Desc "tablename" query. Get the recordcount from the recordset. The count you get is the column count.

      A 1 Reply Last reply
      0
      • B bamboo

        Hi all the guru, I am currently using ODBC to access MS SQL. Can anybody tell me how to get number of columns if given table name? Thanks thanks thanks!!!:eek: vivi

        B Offline
        B Offline
        BlackDice
        wrote on last edited by
        #3

        If you have MSDN I would also suggest searching for the file "catsets.h". This is a bunch of CRecordset-derived classes that allow you to use a table name to get the names, types, and everything else you want to know about the columns. There's also ones to list all the tables, stored procedures,queries, views, primary keys, foreign keys, etc. Hope this helps!! If it's broken, I probably did it bdiamond

        1 Reply Last reply
        0
        • V vikram attiganal

          Try Desc "tablename" query. Get the recordcount from the recordset. The count you get is the column count.

          A Offline
          A Offline
          Alexander Wiseman
          wrote on last edited by
          #4

          Vikram, You need to be careful if you are suggesting to use CRecordset's GetRecordCount() function. According to MSDN, this function only returns the number of seen records in the set. So, right after opening the set, the function will return only 1. You would want to execute another SQL query that counts the records in the resulting set using the COUNT aggregate, or (more inefficiently) loop through the recordset with CRecordset, and then call GetRecordCount(). If your suggestion did not depend upon CRecordset, this, of course, doesn't matter. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem

          B 1 Reply Last reply
          0
          • A Alexander Wiseman

            Vikram, You need to be careful if you are suggesting to use CRecordset's GetRecordCount() function. According to MSDN, this function only returns the number of seen records in the set. So, right after opening the set, the function will return only 1. You would want to execute another SQL query that counts the records in the resulting set using the COUNT aggregate, or (more inefficiently) loop through the recordset with CRecordset, and then call GetRecordCount(). If your suggestion did not depend upon CRecordset, this, of course, doesn't matter. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem

            B Offline
            B Offline
            BlackDice
            wrote on last edited by
            #5

            I was also told the same thing that you just said, but was told to use MoveLast, then MoveFirst, and the count should be right. ;) If it's broken, I probably did it bdiamond

            A 1 Reply Last reply
            0
            • B BlackDice

              I was also told the same thing that you just said, but was told to use MoveLast, then MoveFirst, and the count should be right. ;) If it's broken, I probably did it bdiamond

              A Offline
              A Offline
              Alexander Wiseman
              wrote on last edited by
              #6

              Hmm, that's interesting. I've never tried that, but MSDN says this: [MSDN] Caution The record count is maintained as a "high water mark," the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count. [/MSDN] It might work, though that paragraph seems to mention it specifically. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem

              B 1 Reply Last reply
              0
              • A Alexander Wiseman

                Hmm, that's interesting. I've never tried that, but MSDN says this: [MSDN] Caution The record count is maintained as a "high water mark," the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count. [/MSDN] It might work, though that paragraph seems to mention it specifically. Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem

                B Offline
                B Offline
                BlackDice
                wrote on last edited by
                #7

                I've never seen that before, so thanks!! BTW, when I was told this it was in reference to an ADO recordset object I was using in VB; don't know if that makes any difference. If it's broken, I probably did it bdiamond

                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