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. Database & SysAdmin
  3. Database
  4. Getting data related to what has been selected randomly from a database

Getting data related to what has been selected randomly from a database

Scheduled Pinned Locked Moved Database
databasequestionhelp
7 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.
  • L Offline
    L Offline
    LucBite
    wrote on last edited by
    #1

    I have a Questions table in my database where the quuestiions are selected randomly using the following code "public DataTable getQuestion(string concept,string questiontype) {//gives the user the question for the concept selected above string sql = ""; if (concept == "basic") { sql = "SELECT Question FROM Questions WHERE ConceptId LIKE 'BC%'AND QuestionType ='" + questiontype + "' Order by NewId()"; } else if (Concept == "programming") { sql = "SELECT Question FROM Questions WHERE ConceptId LIKE 'PC%'AND QuestionType ='" + questiontype + "'Order by NewId()"; } return dc.load(sql);//dc is an object of data connection class } Another question type is of multiple choice.And for this type of question there's an Options Table which I need to get the options of the question selected randomly using the code above. Any idea how I can do that? Please help.

    ML Lingwati

    V 1 Reply Last reply
    0
    • L LucBite

      I have a Questions table in my database where the quuestiions are selected randomly using the following code "public DataTable getQuestion(string concept,string questiontype) {//gives the user the question for the concept selected above string sql = ""; if (concept == "basic") { sql = "SELECT Question FROM Questions WHERE ConceptId LIKE 'BC%'AND QuestionType ='" + questiontype + "' Order by NewId()"; } else if (Concept == "programming") { sql = "SELECT Question FROM Questions WHERE ConceptId LIKE 'PC%'AND QuestionType ='" + questiontype + "'Order by NewId()"; } return dc.load(sql);//dc is an object of data connection class } Another question type is of multiple choice.And for this type of question there's an Options Table which I need to get the options of the question selected randomly using the code above. Any idea how I can do that? Please help.

      ML Lingwati

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      Good day LucBite Can you explain Briefly what is your Problem. i understand what you are trying to do, but can you tell us what exactly is your problem

      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

      L 1 Reply Last reply
      0
      • V Vimalsoft Pty Ltd

        Good day LucBite Can you explain Briefly what is your Problem. i understand what you are trying to do, but can you tell us what exactly is your problem

        Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

        L Offline
        L Offline
        LucBite
        wrote on last edited by
        #3

        How do I select the options of a multiple choice question, for the multiple choice question that I selected randomly. Remember, I can't select the options randomly because they have to match the question even though the questiion is selected randomly. The questions are from the Questions Table and the options are from the Options Table. I hope I'm clear please help.

        ML Lingwati

        V B D J 4 Replies Last reply
        0
        • L LucBite

          How do I select the options of a multiple choice question, for the multiple choice question that I selected randomly. Remember, I can't select the options randomly because they have to match the question even though the questiion is selected randomly. The questions are from the Questions Table and the options are from the Options Table. I hope I'm clear please help.

          ML Lingwati

          V Offline
          V Offline
          Vimalsoft Pty Ltd
          wrote on last edited by
          #4

          Good day LucBite You did Explain Clearly again so that i cannot understand better, remember you showed us a Function that return a datatable, now when i said explain clearly i mean to tell us where does the parameters get passed from(UI or Another Function). I Assume you are trying to do something like this You have a Testing Application, First you have Different type of Test "Basic", "Programming" and "MultipleChoice" Now you can select Randomly for "Basic" and "Programming" But you cannot select Randomly for "MultipleChoice" So you want it to be able to select for "MultipleChoice" Questions Randomly" This is how i understand it ,before i give you a solution , i would like to if am right else explain more give me more info

          Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

          1 Reply Last reply
          0
          • L LucBite

            How do I select the options of a multiple choice question, for the multiple choice question that I selected randomly. Remember, I can't select the options randomly because they have to match the question even though the questiion is selected randomly. The questions are from the Questions Table and the options are from the Options Table. I hope I'm clear please help.

            ML Lingwati

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            LucBite wrote:

            hope I'm clear please help.

            Not definitly not.


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            1 Reply Last reply
            0
            • L LucBite

              How do I select the options of a multiple choice question, for the multiple choice question that I selected randomly. Remember, I can't select the options randomly because they have to match the question even though the questiion is selected randomly. The questions are from the Questions Table and the options are from the Options Table. I hope I'm clear please help.

              ML Lingwati

              D Offline
              D Offline
              DoctorMick
              wrote on last edited by
              #6

              So, for a multiple choice question type you want to return random questions and, for each of the questions returned, the applicable options? If I were you, I'd change your sql to return 2 columns for multiple choice, the question text and the id (the primary key on the question table). From there, you can select the options from the appropriate table using the id of the question.

              1 Reply Last reply
              0
              • L LucBite

                How do I select the options of a multiple choice question, for the multiple choice question that I selected randomly. Remember, I can't select the options randomly because they have to match the question even though the questiion is selected randomly. The questions are from the Questions Table and the options are from the Options Table. I hope I'm clear please help.

                ML Lingwati

                J Offline
                J Offline
                Jerry Hammond
                wrote on last edited by
                #7

                LucBite wrote:

                How do I select the options of a multiple choice question, for the multiple choice question that I selected randomly. Remember, I can't select the options randomly because they have to match the question even though the questiion is selected randomly. The questions are from the Questions Table and the options are from the Options Table. I hope I'm clear please help.

                I'm not absolutely sure I understand your question, but this is what I think you might be asking for:

                class SwitchTest 
                

                {
                static void Main()
                {
                Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
                Console.Write("Please enter your selection: ");
                string s = Console.ReadLine();
                int n = int.Parse(s);
                int cost = 0;
                switch(n)
                {
                case 1:
                cost += 25;
                break;
                case 2:
                cost += 25;
                goto case 1;
                case 3:
                cost += 50;
                goto case 1;
                default:
                Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
                break;
                }
                if (cost != 0)
                {
                Console.WriteLine("Please insert {0} cents.", cost);
                }
                Console.WriteLine("Thank you for your business.");
                }
                }
                /*
                Sample Input: 2

                    Sample Output:
                    Coffee sizes: 1=Small 2=Medium 3=Large
                    Please enter your selection: 2
                    Please insert 50 cents.
                    Thank you for your business.
                \*/
                

                "My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering

                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