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. Web Development
  3. ASP.NET
  4. How to get Total count of records from database?

How to get Total count of records from database?

Scheduled Pinned Locked Moved ASP.NET
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.
  • C Offline
    C Offline
    clife537
    wrote on last edited by
    #1

    Hi All, I just want to know how to get the total number of records in the database, i.e from the perticular table, total number of records stored in the table. Please can any one help me. :(

    chandu

    C K F 3 Replies Last reply
    0
    • C clife537

      Hi All, I just want to know how to get the total number of records in the database, i.e from the perticular table, total number of records stored in the table. Please can any one help me. :(

      chandu

      C Offline
      C Offline
      Chetan Ranpariya
      wrote on last edited by
      #2

      HI, SELECT COUNT(*) FROM TABLENAME;

      Thanks and Regards, Chetan Ranpariya

      1 Reply Last reply
      0
      • C clife537

        Hi All, I just want to know how to get the total number of records in the database, i.e from the perticular table, total number of records stored in the table. Please can any one help me. :(

        chandu

        K Offline
        K Offline
        koolprasad2003
        wrote on last edited by
        #3

        hi chandu, To get a total number of records fire this query select count(*) from tableName hope it helps -koolprasad2003:)

        If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy

        1 Reply Last reply
        0
        • C clife537

          Hi All, I just want to know how to get the total number of records in the database, i.e from the perticular table, total number of records stored in the table. Please can any one help me. :(

          chandu

          F Offline
          F Offline
          Fred_Smith
          wrote on last edited by
          #4

          I could be wrong, but rather than use the suggestions above, I think it is quicker / more efficient (for large databases anyway) to use something like select count(ID) from [tableName] Assuming your table has an ID field.... (otherwise, I dare say any fieldname would do, but again, an Int type probably would be most efficient.) Someone may correct me.... Fred

          C 1 Reply Last reply
          0
          • F Fred_Smith

            I could be wrong, but rather than use the suggestions above, I think it is quicker / more efficient (for large databases anyway) to use something like select count(ID) from [tableName] Assuming your table has an ID field.... (otherwise, I dare say any fieldname would do, but again, an Int type probably would be most efficient.) Someone may correct me.... Fred

            C Offline
            C Offline
            clife537
            wrote on last edited by
            #5

            How to print the results of the "SELECT COUNT(*) from Table name".

            chandu

            F 1 Reply Last reply
            0
            • C clife537

              How to print the results of the "SELECT COUNT(*) from Table name".

              chandu

              F Offline
              F Offline
              Fred_Smith
              wrote on last edited by
              #6

              Same way you print anything... you have to read the result into a variable and print it. You can use the ExecuteScalar command on a Command object to read the number directly into a variable - eg, in VB, SQLServer: Dim objCmd As SqlCommand Dim n As Integer, s As String ... objCmd.CommandText = "SELECT COUNT(ID) FROM TableName" n = objCmd.ExecuteScalar ... s = "There are " & n.ToString & " records in the database."

              C 1 Reply Last reply
              0
              • F Fred_Smith

                Same way you print anything... you have to read the result into a variable and print it. You can use the ExecuteScalar command on a Command object to read the number directly into a variable - eg, in VB, SQLServer: Dim objCmd As SqlCommand Dim n As Integer, s As String ... objCmd.CommandText = "SELECT COUNT(ID) FROM TableName" n = objCmd.ExecuteScalar ... s = "There are " & n.ToString & " records in the database."

                C Offline
                C Offline
                clife537
                wrote on last edited by
                #7

                Thanks A loooooooot.......... I am a fresher in to asp.net. thanks for helping.[:)]

                chandu

                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