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#
  4. Save data

Save data

Scheduled Pinned Locked Moved C#
csharphelpquestiondatabasetutorial
5 Posts 2 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.
  • S Offline
    S Offline
    Star09
    wrote on last edited by
    #1

    Hello, I'm building an application in the .Net environment with C#, my program is supposed to retrieve data from a database, no problem here, display it, and based on user input after he presses the next button, the information should be saved as he moves along until the end of the program to display the result. A simple example is like a quiz application, one question at a time, where at the end you calculate the result, and tell the user which questions he got wrong. So, how can I save the result and incorrect questions every time he clicks next button. Sorry for the lengthy explanation. Awaiting your help. :doh: Star :)

    OriginalGriffO 1 Reply Last reply
    0
    • S Star09

      Hello, I'm building an application in the .Net environment with C#, my program is supposed to retrieve data from a database, no problem here, display it, and based on user input after he presses the next button, the information should be saved as he moves along until the end of the program to display the result. A simple example is like a quiz application, one question at a time, where at the end you calculate the result, and tell the user which questions he got wrong. So, how can I save the result and incorrect questions every time he clicks next button. Sorry for the lengthy explanation. Awaiting your help. :doh: Star :)

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      I may have missed the point completely, but can't you just set up a class to hold the info you want, and add an instance of each to a List for processing later? No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      S 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        I may have missed the point completely, but can't you just set up a class to hold the info you want, and add an instance of each to a List for processing later? No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        S Offline
        S Offline
        Star09
        wrote on last edited by
        #3

        I do have a class, but does it save the results throughout the program?

        OriginalGriffO 1 Reply Last reply
        0
        • S Star09

          I do have a class, but does it save the results throughout the program?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          This is not the recommended way to do this, but I am a little pushed for time...

          using System;
          using System.Collections.Generic;

          namespace Demo
          {
          class SaveResults
          {
          public string results;
          }

          class Program
              {
              public static List listResults = new List();
              static void Main(string\[\] args)
                  {
                  // blah de blah
                  foreach (SaveResults sr in listResults)
                      {
                      // Handle results
                      Console.WriteLine(sr.results);
                      }
                  }
              }
          
          class Processing
              {
              void DoSomething()
                  {
                  // Blah de blah
                  SaveResults sr = new SaveResults();
                  sr.results = "hello";
                  Program.listResults.Add(sr);
                  }
              }
          }
          

          Each time you get results, you create a new instance of the SaveResults class, storing the info you need later (Processing.DoSomething). You then add this to a static list (in program class here so that it persists until the app ends - you will have a better place, I am sure). When all processing is done, just iterrate through the List and handle each answer in turn.

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          S 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            This is not the recommended way to do this, but I am a little pushed for time...

            using System;
            using System.Collections.Generic;

            namespace Demo
            {
            class SaveResults
            {
            public string results;
            }

            class Program
                {
                public static List listResults = new List();
                static void Main(string\[\] args)
                    {
                    // blah de blah
                    foreach (SaveResults sr in listResults)
                        {
                        // Handle results
                        Console.WriteLine(sr.results);
                        }
                    }
                }
            
            class Processing
                {
                void DoSomething()
                    {
                    // Blah de blah
                    SaveResults sr = new SaveResults();
                    sr.results = "hello";
                    Program.listResults.Add(sr);
                    }
                }
            }
            

            Each time you get results, you create a new instance of the SaveResults class, storing the info you need later (Processing.DoSomething). You then add this to a static list (in program class here so that it persists until the app ends - you will have a better place, I am sure). When all processing is done, just iterrate through the List and handle each answer in turn.

            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

            S Offline
            S Offline
            Star09
            wrote on last edited by
            #5

            Thank you for taking the time to explain it, I appreciate it. :) :)

            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