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. Finding a record by its primary key

Finding a record by its primary key

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasesql-serversysadminbusinesshelp
19 Posts 10 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 Chris Quinn

    When I joined my current company about three years ago, I was given the task of maintaining the company's business critical order processing system. This is written as an Access front end to a SQL Server back end, and was written by a contractor who had left at the end of his contract with a large amount of the company's money in his bank account! Some investigation after my first week or two lead me to discover the following horrors: There was not a single error trapping routine in the whole front end - if something fell over, the standard error message was "an error occurred in the click event of btn....." Each routine that inserted a record was written as a Sub, rather than a function that returned a success/failure value. Every user on the database was assigned DBO permissions! There was absolutely no referential integrity defined in the database. There was no transaction processing in the system - if someting fell over part way through (as it often did), updates/inserts/deletes had to be rolled back manually using Enterprise manager. An example of his coding style is shown here - it shows how he retrieved a single record using its primary key:

        Set rstMain = New ADODB.Recordset
        Set cmd = New ADODB.Command
        cmd.ActiveConnection = CurrentProject.Connection
        cmd.CommandText = "spSELocationForSageImport"
        Set prm = cmd.CreateParameter("@LocationCode", adVarChar, adParamInput, 20, "Sage")
        cmd.Parameters.Append prm
        cmd.CommandType = adCmdStoredProc
        rstMain.Open cmd, , adOpenDynamic, adLockOptimistic, adCmdStoredProc
    
        With rstMain
            Do While Not .EOF
                strLocation = !\[Location\]
                .MoveNext
            Loop
        End With
        Set rstMain = Nothing
    

    Maybe I'm missing something, but do you need to loop though a dataset that can only contain one record? His date handling was also a bit esoteric:

        txtDateCreated = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
    

    I recently had occasion to rewrite some of his code that applied changes from an external system to the database. His code took two or more hours to run and slowed the system so much it was unusable (meaning I usually had to do unpaid overtime to apply the data out of hours). One of the lovely bits of code he wrote looped through a data set of 7000+ records, taking a value from each record and using this as a parameter in a stored procedure t

    P Offline
    P Offline
    Paul Conrad
    wrote on last edited by
    #5

    As the others have said, it does look like he found some example and kept using it over and over. Pretty much any VBA coding in Access is a strong candidate for being a coding horror.

    "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

    C S 2 Replies Last reply
    0
    • P Paul Conrad

      As the others have said, it does look like he found some example and kept using it over and over. Pretty much any VBA coding in Access is a strong candidate for being a coding horror.

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

      C Offline
      C Offline
      Chris Quinn
      wrote on last edited by
      #6

      I don't agree - it's not the tool you use - it's the tool that uses it!

      ==================================== Transvestites - Roberts in Disguise! ====================================

      P 1 Reply Last reply
      0
      • C Chris Quinn

        I don't agree - it's not the tool you use - it's the tool that uses it!

        ==================================== Transvestites - Roberts in Disguise! ====================================

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #7

        True. Access can be alright when used correctly.

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

        P 1 Reply Last reply
        0
        • P Paul Conrad

          True. Access can be alright when used correctly.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #8

          By default, Access should be removed from the PC of anybody who is tempted to open it up and knock together a crappy app with zero understanding of basic database procedures. Hello. It's called normalization people, and it's not an optional extra. If you don't understand normalisation, then you should be in a more touchy-feely career and not one that demands reaching higher than a 2 on the clue-o-meter.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          D P 2 Replies Last reply
          0
          • P Pete OHanlon

            By default, Access should be removed from the PC of anybody who is tempted to open it up and knock together a crappy app with zero understanding of basic database procedures. Hello. It's called normalization people, and it's not an optional extra. If you don't understand normalisation, then you should be in a more touchy-feely career and not one that demands reaching higher than a 2 on the clue-o-meter.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

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

            Yeah. Anyone wanting to use access should in addition to being required to pass the 'not excel' test for data design, also understand why changes are saved immediately instead of when you click the save icon. [my younger sister}, who creates single flat table dbs and never manages to grasp why I explain it isn't bundled in the cheap version of office, I mean you. :mad:

            Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

            P D 2 Replies Last reply
            0
            • P Pete OHanlon

              By default, Access should be removed from the PC of anybody who is tempted to open it up and knock together a crappy app with zero understanding of basic database procedures. Hello. It's called normalization people, and it's not an optional extra. If you don't understand normalisation, then you should be in a more touchy-feely career and not one that demands reaching higher than a 2 on the clue-o-meter.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #10

              Pete O'Hanlon wrote:

              Access should be removed from the PC of anybody who is tempted to open it up and knock together a crappy app with zero understanding of basic database procedures. Hello. It's called normalization people, and it's not an optional extra. If you don't understand normalisation, then you should be in a more touchy-feely career and not one that demands reaching higher than a 2 on the clue-o-meter.

              Amen to that :)

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              1 Reply Last reply
              0
              • D Dan Neely

                Yeah. Anyone wanting to use access should in addition to being required to pass the 'not excel' test for data design, also understand why changes are saved immediately instead of when you click the save icon. [my younger sister}, who creates single flat table dbs and never manages to grasp why I explain it isn't bundled in the cheap version of office, I mean you. :mad:

                Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #11

                dan neely wrote:

                it isn't bundled in the cheap version of office

                Thanks to God for that :) We have Access 2007 installed in the labs at my college where I teach and I took one look at it, and never looked at it again :laugh:

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                1 Reply Last reply
                0
                • P Paul Conrad

                  As the others have said, it does look like he found some example and kept using it over and over. Pretty much any VBA coding in Access is a strong candidate for being a coding horror.

                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                  S Offline
                  S Offline
                  SilimSayo
                  wrote on last edited by
                  #12

                  Comeon I have written several VBA programs both nothing as horrible as that.

                  N 1 Reply Last reply
                  0
                  • S SilimSayo

                    Comeon I have written several VBA programs both nothing as horrible as that.

                    N Offline
                    N Offline
                    Nathan Tuggy
                    wrote on last edited by
                    #13

                    Sad: I have to maintain

                    1 Reply Last reply
                    0
                    • C Chris Quinn

                      When I joined my current company about three years ago, I was given the task of maintaining the company's business critical order processing system. This is written as an Access front end to a SQL Server back end, and was written by a contractor who had left at the end of his contract with a large amount of the company's money in his bank account! Some investigation after my first week or two lead me to discover the following horrors: There was not a single error trapping routine in the whole front end - if something fell over, the standard error message was "an error occurred in the click event of btn....." Each routine that inserted a record was written as a Sub, rather than a function that returned a success/failure value. Every user on the database was assigned DBO permissions! There was absolutely no referential integrity defined in the database. There was no transaction processing in the system - if someting fell over part way through (as it often did), updates/inserts/deletes had to be rolled back manually using Enterprise manager. An example of his coding style is shown here - it shows how he retrieved a single record using its primary key:

                          Set rstMain = New ADODB.Recordset
                          Set cmd = New ADODB.Command
                          cmd.ActiveConnection = CurrentProject.Connection
                          cmd.CommandText = "spSELocationForSageImport"
                          Set prm = cmd.CreateParameter("@LocationCode", adVarChar, adParamInput, 20, "Sage")
                          cmd.Parameters.Append prm
                          cmd.CommandType = adCmdStoredProc
                          rstMain.Open cmd, , adOpenDynamic, adLockOptimistic, adCmdStoredProc
                      
                          With rstMain
                              Do While Not .EOF
                                  strLocation = !\[Location\]
                                  .MoveNext
                              Loop
                          End With
                          Set rstMain = Nothing
                      

                      Maybe I'm missing something, but do you need to loop though a dataset that can only contain one record? His date handling was also a bit esoteric:

                          txtDateCreated = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
                      

                      I recently had occasion to rewrite some of his code that applied changes from an external system to the database. His code took two or more hours to run and slowed the system so much it was unusable (meaning I usually had to do unpaid overtime to apply the data out of hours). One of the lovely bits of code he wrote looped through a data set of 7000+ records, taking a value from each record and using this as a parameter in a stored procedure t

                      N Offline
                      N Offline
                      Nathan Tuggy
                      wrote on last edited by
                      #14

                      Sad: I have to maintain code like this.

                      1 Reply Last reply
                      0
                      • D Dan Neely

                        Yeah. Anyone wanting to use access should in addition to being required to pass the 'not excel' test for data design, also understand why changes are saved immediately instead of when you click the save icon. [my younger sister}, who creates single flat table dbs and never manages to grasp why I explain it isn't bundled in the cheap version of office, I mean you. :mad:

                        Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                        D Offline
                        D Offline
                        developer6
                        wrote on last edited by
                        #15

                        At the risk of sounding like a fool, could I ask you to please explain the bit about changes being saved immediately instead of when the save icon is clicked.

                        P 1 Reply Last reply
                        0
                        • D developer6

                          At the risk of sounding like a fool, could I ask you to please explain the bit about changes being saved immediately instead of when the save icon is clicked.

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #16

                          Databases have implicit save behaviour, e.g. triggered by an action such as moving to a new row. An application like Excel does not know when you want to save the data, so it only saves when you trigger an explicit save.

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          D 1 Reply Last reply
                          0
                          • P Pete OHanlon

                            Databases have implicit save behaviour, e.g. triggered by an action such as moving to a new row. An application like Excel does not know when you want to save the data, so it only saves when you trigger an explicit save.

                            Deja View - the feeling that you've seen this post before.

                            My blog | My articles

                            D Offline
                            D Offline
                            developer6
                            wrote on last edited by
                            #17

                            Okey doke -- but this is only the case when there is data binding between the database and the client right? I'm sure there must be plenty of apps out there, other than Excel, that required an explicit save. I'm not sure if I get the point that was originally being made. Was this being suggested as a good thing, a bad thing, or just an example of where the "developer" mis-understood what was going on?

                            D 1 Reply Last reply
                            0
                            • D developer6

                              Okey doke -- but this is only the case when there is data binding between the database and the client right? I'm sure there must be plenty of apps out there, other than Excel, that required an explicit save. I'm not sure if I get the point that was originally being made. Was this being suggested as a good thing, a bad thing, or just an example of where the "developer" mis-understood what was going on?

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

                              This was a case of a luser insisting on using the wrong tool (access instead of excel), and then continually whining about how it didn't do what she wanted.

                              Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                              1 Reply Last reply
                              0
                              • C Chris Quinn

                                When I joined my current company about three years ago, I was given the task of maintaining the company's business critical order processing system. This is written as an Access front end to a SQL Server back end, and was written by a contractor who had left at the end of his contract with a large amount of the company's money in his bank account! Some investigation after my first week or two lead me to discover the following horrors: There was not a single error trapping routine in the whole front end - if something fell over, the standard error message was "an error occurred in the click event of btn....." Each routine that inserted a record was written as a Sub, rather than a function that returned a success/failure value. Every user on the database was assigned DBO permissions! There was absolutely no referential integrity defined in the database. There was no transaction processing in the system - if someting fell over part way through (as it often did), updates/inserts/deletes had to be rolled back manually using Enterprise manager. An example of his coding style is shown here - it shows how he retrieved a single record using its primary key:

                                    Set rstMain = New ADODB.Recordset
                                    Set cmd = New ADODB.Command
                                    cmd.ActiveConnection = CurrentProject.Connection
                                    cmd.CommandText = "spSELocationForSageImport"
                                    Set prm = cmd.CreateParameter("@LocationCode", adVarChar, adParamInput, 20, "Sage")
                                    cmd.Parameters.Append prm
                                    cmd.CommandType = adCmdStoredProc
                                    rstMain.Open cmd, , adOpenDynamic, adLockOptimistic, adCmdStoredProc
                                
                                    With rstMain
                                        Do While Not .EOF
                                            strLocation = !\[Location\]
                                            .MoveNext
                                        Loop
                                    End With
                                    Set rstMain = Nothing
                                

                                Maybe I'm missing something, but do you need to loop though a dataset that can only contain one record? His date handling was also a bit esoteric:

                                    txtDateCreated = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
                                

                                I recently had occasion to rewrite some of his code that applied changes from an external system to the database. His code took two or more hours to run and slowed the system so much it was unusable (meaning I usually had to do unpaid overtime to apply the data out of hours). One of the lovely bits of code he wrote looped through a data set of 7000+ records, taking a value from each record and using this as a parameter in a stored procedure t

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #19

                                Transactions are a blessing. Writing code to undo all changes after an error is no fun at all. And how do you proceed when even more errors pop up while undoing things? Unfortunately you don't always have transactions. I'm working on a larger project that uses a MySql database for both low cost and speed. Using another table format would make transactions available, but also slow everything down in an unacceptable manner. So I guess, the only choice is dealing with some tight spots in the buisiness logic.

                                A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                                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