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. Reading multiple records from a database

Reading multiple records from a database

Scheduled Pinned Locked Moved C#
databasedesignsysadmindata-structureshelp
8 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.
  • F Offline
    F Offline
    ferronrsmith
    wrote on last edited by
    #1

    i wanna pull multiple records in from a database and display them in different labels I was thinking of returning them in an array then adding them to the specified labels, can anyone point me to the an example or aid me. sample code

    public partial class _Default : System.Web.UI.Page
    {
    SqlConnection con = new SqlConnection("server=BABOO;uid=sa;password=sa;database=quiz");
    protected void Page_Load(object sender, EventArgs e)
    {
    con.Open();
    string query;
    query = "select QuestionText,AnswerA,AnswerB,AnswerC,AnswerD from quest where QuestionID='1'";
    SqlCommand cmd = new SqlCommand(query, con);
    SqlDataReader dr;
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
    nt rbCount = Convert.ToInt32(TextBox2.Text);
    //iin textbox enter how many record want to display
    RadioButton[] radioButtons = new RadioButton[rbCount];
    for (int i = 0; i < rbCount; ++i)
    {
    radioButtons[i] = new RadioButton();

    radioButtons[i].Text = dr.GetValue(1).ToString();
    }

    Please i need your help

    Ferron

    C 1 Reply Last reply
    0
    • F ferronrsmith

      i wanna pull multiple records in from a database and display them in different labels I was thinking of returning them in an array then adding them to the specified labels, can anyone point me to the an example or aid me. sample code

      public partial class _Default : System.Web.UI.Page
      {
      SqlConnection con = new SqlConnection("server=BABOO;uid=sa;password=sa;database=quiz");
      protected void Page_Load(object sender, EventArgs e)
      {
      con.Open();
      string query;
      query = "select QuestionText,AnswerA,AnswerB,AnswerC,AnswerD from quest where QuestionID='1'";
      SqlCommand cmd = new SqlCommand(query, con);
      SqlDataReader dr;
      dr = cmd.ExecuteReader();
      while (dr.Read())
      {
      nt rbCount = Convert.ToInt32(TextBox2.Text);
      //iin textbox enter how many record want to display
      RadioButton[] radioButtons = new RadioButton[rbCount];
      for (int i = 0; i < rbCount; ++i)
      {
      radioButtons[i] = new RadioButton();

      radioButtons[i].Text = dr.GetValue(1).ToString();
      }

      Please i need your help

      Ferron

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      So, this seems a little retarded to me. 1 - you want to have a textbox showing how many answers to show ? So, what if the right answer gets hidden ? 2 - how do you make sure that textbox2 contains a number ? 3 - why don't your variables have real names ? 4 - You're reading the same value from the answer list every time 5 - you never add the radio buttons to your UI

      Christian Graus Driven to the arms of OSX by Vista.

      F 1 Reply Last reply
      0
      • C Christian Graus

        So, this seems a little retarded to me. 1 - you want to have a textbox showing how many answers to show ? So, what if the right answer gets hidden ? 2 - how do you make sure that textbox2 contains a number ? 3 - why don't your variables have real names ? 4 - You're reading the same value from the answer list every time 5 - you never add the radio buttons to your UI

        Christian Graus Driven to the arms of OSX by Vista.

        F Offline
        F Offline
        ferronrsmith
        wrote on last edited by
        #3

        i know, that's why i need your help to sort it out the write way. basically what i have is 3 textbox text[1] text[2] text[3] if three records are in the database it should bring back three sets of record all in their respective textbox. Plz can u help

        Ferron

        C 1 Reply Last reply
        0
        • F ferronrsmith

          i know, that's why i need your help to sort it out the write way. basically what i have is 3 textbox text[1] text[2] text[3] if three records are in the database it should bring back three sets of record all in their respective textbox. Plz can u help

          Ferron

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          So the possible answers go in textboxes, not in radio buttons ? Are you saying the number of answers is flexible ? I would do this with a data bound control, assuming I had to show more than one question on a page.

          Christian Graus Driven to the arms of OSX by Vista.

          F 1 Reply Last reply
          0
          • C Christian Graus

            So the possible answers go in textboxes, not in radio buttons ? Are you saying the number of answers is flexible ? I would do this with a data bound control, assuming I had to show more than one question on a page.

            Christian Graus Driven to the arms of OSX by Vista.

            F Offline
            F Offline
            ferronrsmith
            wrote on last edited by
            #5

            Yes I want to show the results in the text box? I have it created in a form. Is the the data bound control flexible? Can the realit be formatted in a form like manner, for say a application form?

            Ferron

            C 1 Reply Last reply
            0
            • F ferronrsmith

              Yes I want to show the results in the text box? I have it created in a form. Is the the data bound control flexible? Can the realit be formatted in a form like manner, for say a application form?

              Ferron

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Yeah, you can define a template for a data bound control and show the data any way you like.

              Christian Graus Driven to the arms of OSX by Vista.

              F 2 Replies Last reply
              0
              • C Christian Graus

                Yeah, you can define a template for a data bound control and show the data any way you like.

                Christian Graus Driven to the arms of OSX by Vista.

                F Offline
                F Offline
                ferronrsmith
                wrote on last edited by
                #7

                I have used a form view, its working well, the thing is how do I get it to display records one under the other instead of paging?

                Ferron

                1 Reply Last reply
                0
                • C Christian Graus

                  Yeah, you can define a template for a data bound control and show the data any way you like.

                  Christian Graus Driven to the arms of OSX by Vista.

                  F Offline
                  F Offline
                  ferronrsmith
                  wrote on last edited by
                  #8

                  I used a data list control to display all my records, but i have been trying to add paging capability. :(

                  Ferron

                  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