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. How to waste time calling the database multiple times

How to waste time calling the database multiple times

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasetutorialquestion
5 Posts 5 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.
  • N Offline
    N Offline
    Nathan D Cook
    wrote on last edited by
    #1

    Names changed to protect the innocent....

    private void FillGrid()
    {
    /*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
    }

    /*handler called for certain changes to the Case*/
    private void Case_SelectionChanged(object sender, EventArgs e)
    {
    FillGrid();
    }

    private void FillCase(string PatientID)
    {
    /*(some meaningless code ommitted)*/

    case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
    }

    /*called EVERY time we search...*/
    protected void Search()
    {
    FillCase(PatientID);
    case.EditValue = caseNo.Trim(); /*fires the same handler*/
    Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
    FillGrid();
    }

    So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:

    B L P 3 Replies Last reply
    0
    • N Nathan D Cook

      Names changed to protect the innocent....

      private void FillGrid()
      {
      /*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
      }

      /*handler called for certain changes to the Case*/
      private void Case_SelectionChanged(object sender, EventArgs e)
      {
      FillGrid();
      }

      private void FillCase(string PatientID)
      {
      /*(some meaningless code ommitted)*/

      case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
      }

      /*called EVERY time we search...*/
      protected void Search()
      {
      FillCase(PatientID);
      case.EditValue = caseNo.Trim(); /*fires the same handler*/
      Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
      FillGrid();
      }

      So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      That example is not complete, is it? All of the functions you show are private/protected, none is public, and only one gets called by a user interaction. The real fun must be somewhere else. Didn't you see a function like:

      private void Button1_Click(object sender, EventArgs e)
      {
      //remove the previous selection
      FillCase("");
      Search();
      Case_SelectionChanged(new object(), new EventArgs());
      FillGrid();
      //get fresh data and show them
      FillCase("some value");
      Search();
      Case_SelectionChanged(new object(), new EventArgs());
      FillGrid();
      //make sure that it is really the data of the selected case which are shown
      ... and some more lines of code
      }

      1 Reply Last reply
      0
      • N Nathan D Cook

        Names changed to protect the innocent....

        private void FillGrid()
        {
        /*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
        }

        /*handler called for certain changes to the Case*/
        private void Case_SelectionChanged(object sender, EventArgs e)
        {
        FillGrid();
        }

        private void FillCase(string PatientID)
        {
        /*(some meaningless code ommitted)*/

        case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
        }

        /*called EVERY time we search...*/
        protected void Search()
        {
        FillCase(PatientID);
        case.EditValue = caseNo.Trim(); /*fires the same handler*/
        Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
        FillGrid();
        }

        So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:

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

        He just wanted to be on the safe side and assured that the grid is filled, no matter what happens :)

        And from the clouds a mighty voice spoke:
        "Smile and be happy, for it could come worse!"

        And I smiled and was happy
        And it came worse.

        Sander RosselS 1 Reply Last reply
        0
        • L Lost User

          He just wanted to be on the safe side and assured that the grid is filled, no matter what happens :)

          And from the clouds a mighty voice spoke:
          "Smile and be happy, for it could come worse!"

          And I smiled and was happy
          And it came worse.

          Sander RosselS Offline
          Sander RosselS Offline
          Sander Rossel
          wrote on last edited by
          #4

          From what I can see the grid won't actually be filled if the FillGrid throws an Exception. Unless there is a deleted try catch block there that recursively calls the FillGrid Method again in its catch block... :rolleyes:

          It's an OO world.

          public class Naerling : Lazy<Person>{}

          1 Reply Last reply
          0
          • N Nathan D Cook

            Names changed to protect the innocent....

            private void FillGrid()
            {
            /*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
            }

            /*handler called for certain changes to the Case*/
            private void Case_SelectionChanged(object sender, EventArgs e)
            {
            FillGrid();
            }

            private void FillCase(string PatientID)
            {
            /*(some meaningless code ommitted)*/

            case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
            }

            /*called EVERY time we search...*/
            protected void Search()
            {
            FillCase(PatientID);
            case.EditValue = caseNo.Trim(); /*fires the same handler*/
            Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
            FillGrid();
            }

            So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:

            P Offline
            P Offline
            prasun r
            wrote on last edited by
            #5

            Did you got the guy fired, cause of such guys the software can't cope up even with hardware advancements. Even with a quad core machines and GBs of RAM we still have the same performance issues we used to have in the days of Pentium I and a few MB of RAM.

            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