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. Other Discussions
  3. The Weird and The Wonderful
  4. Get me a count....

Get me a count....

Scheduled Pinned Locked Moved The Weird and The Wonderful
toolsquestion
26 Posts 17 Posters 5 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.
  • V Vikas Salvi

    I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

    Vikas Salvi Programmer Analyst

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #3

    Version 1.0 probably used a DataAdapter to Fill a DataTable and then counted the Rows. This is an improvement.

    V 1 Reply Last reply
    0
    • P PIEBALDconsult

      Version 1.0 probably used a DataAdapter to Fill a DataTable and then counted the Rows. This is an improvement.

      V Offline
      V Offline
      Vikas Salvi
      wrote on last edited by
      #4

      using a Count(*) query is much simple n straightforward i suppose :-D

      Vikas Salvi Programmer Analyst

      C P 2 Replies Last reply
      0
      • V Vikas Salvi

        using a Count(*) query is much simple n straightforward i suppose :-D

        Vikas Salvi Programmer Analyst

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #5

        And depending upon the database, count(ROWID) might be even better. :)

        Chris Meech I am Canadian. [heard in a local bar]

        1 Reply Last reply
        0
        • V Vikas Salvi

          I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

          Vikas Salvi Programmer Analyst

          R Offline
          R Offline
          Rob Manderson
          wrote on last edited by
          #6

          Check the MFC docs for CRecordset. They specifically advise that the record count isn't known until you've scrolled to the last record and then recommend you do just that if you need the count. A colleague, many years ago, followed that advice. It worked fine on his test databases but when it hit the real world and a recordset containing 3 million records it didn't work quite so well. Interestingly enough, the customer put up with the shocking performance (> 40 minutes for a form refresh). Go figure!

          Rob Manderson My bloghttp://robmanderson.blogspot.com[^]

          D C M 3 Replies Last reply
          0
          • V Vikas Salvi

            using a Count(*) query is much simple n straightforward i suppose :-D

            Vikas Salvi Programmer Analyst

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #7

            Well, yeah, but we have to save that for the next version... if anyone complains about performance that is. Or, if we're very lucky, we'll get to buy new servers to improve performance, and that makes us very happy. :-D

            C X 2 Replies Last reply
            0
            • R Rob Manderson

              Check the MFC docs for CRecordset. They specifically advise that the record count isn't known until you've scrolled to the last record and then recommend you do just that if you need the count. A colleague, many years ago, followed that advice. It worked fine on his test databases but when it hit the real world and a recordset containing 3 million records it didn't work quite so well. Interestingly enough, the customer put up with the shocking performance (> 40 minutes for a form refresh). Go figure!

              Rob Manderson My bloghttp://robmanderson.blogspot.com[^]

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #8

              Rob Manderson wrote:

              Interestingly enough, the customer put up with the shocking performance (> 40 minutes for a form refresh). Go figure!

              Now that's the true WTF. :laugh:

              -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

              S 1 Reply Last reply
              0
              • R Rob Manderson

                Check the MFC docs for CRecordset. They specifically advise that the record count isn't known until you've scrolled to the last record and then recommend you do just that if you need the count. A colleague, many years ago, followed that advice. It worked fine on his test databases but when it hit the real world and a recordset containing 3 million records it didn't work quite so well. Interestingly enough, the customer put up with the shocking performance (> 40 minutes for a form refresh). Go figure!

                Rob Manderson My bloghttp://robmanderson.blogspot.com[^]

                C Offline
                C Offline
                Chris Meech
                wrote on last edited by
                #9

                Of course a good way to speed that up was to use the MoveLast method after the recordset was opened. The count call would then be really responsive, but you'd be scratching your head over why was the count always 2. :rolleyes:

                Chris Meech I am Canadian. [heard in a local bar]

                1 Reply Last reply
                0
                • V Vikas Salvi

                  I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

                  Vikas Salvi Programmer Analyst

                  V Offline
                  V Offline
                  Vasudevan Deepak Kumar
                  wrote on last edited by
                  #10

                  It verifies whether SQLServer is doing a correct job or not. :-D

                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                  1 Reply Last reply
                  0
                  • V Vikas Salvi

                    I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

                    Vikas Salvi Programmer Analyst

                    D Offline
                    D Offline
                    darkelv
                    wrote on last edited by
                    #11

                    The programmer should have done away with the where clause and check UserType in the while loop.....:^)

                    1 Reply Last reply
                    0
                    • V Vikas Salvi

                      I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

                      Vikas Salvi Programmer Analyst

                      N Offline
                      N Offline
                      NormDroid
                      wrote on last edited by
                      #12

                      Thats why I always be in work, people like that create work for everyone. Oh the inexperienced should be allowed to develop commercial code.

                      Roger Irrelevant "he's completely hatstand"

                      1 Reply Last reply
                      0
                      • R Rob Manderson

                        Check the MFC docs for CRecordset. They specifically advise that the record count isn't known until you've scrolled to the last record and then recommend you do just that if you need the count. A colleague, many years ago, followed that advice. It worked fine on his test databases but when it hit the real world and a recordset containing 3 million records it didn't work quite so well. Interestingly enough, the customer put up with the shocking performance (> 40 minutes for a form refresh). Go figure!

                        Rob Manderson My bloghttp://robmanderson.blogspot.com[^]

                        M Offline
                        M Offline
                        Mauro Leggieri
                        wrote on last edited by
                        #13

                        Yes but it should not apply if the query uses "count(*)" becuase the sql server will do the "counting" and return 1 row with the result. Mauro Leggieri.

                        1 Reply Last reply
                        0
                        • V Vikas Salvi

                          I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

                          Vikas Salvi Programmer Analyst

                          J Offline
                          J Offline
                          jhwurmbach
                          wrote on last edited by
                          #14

                          Did he use the wrong incantations?


                          Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                          George Orwell, "Keep the Aspidistra Flying", Opening words

                          K 1 Reply Last reply
                          0
                          • V Vikas Salvi

                            I m really speechless on this.. string strQuery = "Select * from tblExtension where UserType = " + _UserType; int _Count = 0; OleDbDataReader drExtension = OleDbHelper.ExecuteReader(Utility.ConnectionString, CommandType.Text, strQuery); using(drExtension) { while(drExtension.Read()) { ++_Count; } } return _Count; ny comment??

                            Vikas Salvi Programmer Analyst

                            T Offline
                            T Offline
                            Ted Ferenc
                            wrote on last edited by
                            #15

                            Reminds me of one I saw. To alphabetically sort the ASCII data in a table the moron read the relevant field into a fixed length string array and then he sorted the array. And guess what the management did to him? He was promoted to team leader eventually! I kid you not.


                            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for - in order to get to the job you need to pay for the clothes and the car, and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                            R 1 Reply Last reply
                            0
                            • T Ted Ferenc

                              Reminds me of one I saw. To alphabetically sort the ASCII data in a table the moron read the relevant field into a fixed length string array and then he sorted the array. And guess what the management did to him? He was promoted to team leader eventually! I kid you not.


                              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for - in order to get to the job you need to pay for the clothes and the car, and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                              R Offline
                              R Offline
                              Rajesh R Subramanian
                              wrote on last edited by
                              #16

                              Ted Ferenc wrote:

                              And guess what the management did to him? He was promoted to team leader eventually!

                              :wtf::omg:


                              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                              T 1 Reply Last reply
                              0
                              • R Rajesh R Subramanian

                                Ted Ferenc wrote:

                                And guess what the management did to him? He was promoted to team leader eventually!

                                :wtf::omg:


                                Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                                T Offline
                                T Offline
                                Ted Ferenc
                                wrote on last edited by
                                #17

                                The sad thing was the Software Manager, I was going to run a new branch the firm opened so they needed a team leader, my comment was make anybody team leader except him, even the cleaning lady would be a better choice. I did state that within 6 months he would have totally screwed up the work I had done in making the department function at least tolerably well. In 6 months I was proved correct, what happened to him? He left, as he was a team leader, he got a better team leaders job elsewhere!


                                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for - in order to get to the job you need to pay for the clothes and the car, and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                                1 Reply Last reply
                                0
                                • D Dan Neely

                                  Rob Manderson wrote:

                                  Interestingly enough, the customer put up with the shocking performance (> 40 minutes for a form refresh). Go figure!

                                  Now that's the true WTF. :laugh:

                                  -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

                                  S Offline
                                  S Offline
                                  StevenWalsh
                                  wrote on last edited by
                                  #18

                                  add a little spinny thing while it refreshes... they'll wait for hours :)

                                  1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Well, yeah, but we have to save that for the next version... if anyone complains about performance that is. Or, if we're very lucky, we'll get to buy new servers to improve performance, and that makes us very happy. :-D

                                    C Offline
                                    C Offline
                                    Catalin Murariu
                                    wrote on last edited by
                                    #19

                                    The gay guy that rated your post with a 2, obviously didn't catch the sarcasm in it... Some things are too subtle I guess ;P

                                    Asynchronously daydreaming...

                                    1 Reply Last reply
                                    0
                                    • J jhwurmbach

                                      Did he use the wrong incantations?


                                      Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                                      George Orwell, "Keep the Aspidistra Flying", Opening words

                                      K Offline
                                      K Offline
                                      KaRl
                                      wrote on last edited by
                                      #20

                                      To get the count of items in your table, you would be using SQL's countof[^] (unless this is MySQL specific? :~)

                                      1 Reply Last reply
                                      0
                                      • P PIEBALDconsult

                                        Well, yeah, but we have to save that for the next version... if anyone complains about performance that is. Or, if we're very lucky, we'll get to buy new servers to improve performance, and that makes us very happy. :-D

                                        X Offline
                                        X Offline
                                        Xagyg
                                        wrote on last edited by
                                        #21

                                        Gold Canyon, AZ ... where OpenSource means far too much of a reduction in profit margins! :)

                                        P 1 Reply Last reply
                                        0
                                        • X Xagyg

                                          Gold Canyon, AZ ... where OpenSource means far too much of a reduction in profit margins! :)

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #22

                                          Alright, who are you and how do you know where I live? :~

                                          X 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