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. Displaying data one by one using timer

Displaying data one by one using timer

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
11 Posts 3 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.
  • J Offline
    J Offline
    jacklynn_mei
    wrote on last edited by
    #1

    Hi... I have problem with my timer code. I want to display the data from the sql database on textbox using timer tick event. For an example there are 3 data in the database which are apple,banana,coconut. apple will appear first and after 10 seconds banana will appear, and after 10 seconds coconut will appear. And then, after the last data (coconut) appeared, the first data (apple) appeared again, and so on. It will continuously loop. I want to do like this. Any suggestion or reference? Thanks Jac

    V A 2 Replies Last reply
    0
    • J jacklynn_mei

      Hi... I have problem with my timer code. I want to display the data from the sql database on textbox using timer tick event. For an example there are 3 data in the database which are apple,banana,coconut. apple will appear first and after 10 seconds banana will appear, and after 10 seconds coconut will appear. And then, after the last data (coconut) appeared, the first data (apple) appeared again, and so on. It will continuously loop. I want to do like this. Any suggestion or reference? Thanks Jac

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      jacklynn_mei wrote:

      It will continuously loop.

      If you are looking at providing some interactive DHTML effect, I would suggest you look into: http://script.aculo.us/[^]

      Vasudevan Deepak Kumar Personal Homepage
      Tech Gossips
      A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

      1 Reply Last reply
      0
      • J jacklynn_mei

        Hi... I have problem with my timer code. I want to display the data from the sql database on textbox using timer tick event. For an example there are 3 data in the database which are apple,banana,coconut. apple will appear first and after 10 seconds banana will appear, and after 10 seconds coconut will appear. And then, after the last data (coconut) appeared, the first data (apple) appeared again, and so on. It will continuously loop. I want to do like this. Any suggestion or reference? Thanks Jac

        A Offline
        A Offline
        Andrei Ungureanu
        wrote on last edited by
        #3

        Do you want to do this in a web or desktop application?

        I will use Google before asking dumb questions

        J 1 Reply Last reply
        0
        • A Andrei Ungureanu

          Do you want to do this in a web or desktop application?

          I will use Google before asking dumb questions

          J Offline
          J Offline
          jacklynn_mei
          wrote on last edited by
          #4

          Winform Application

          A 1 Reply Last reply
          0
          • J jacklynn_mei

            Winform Application

            A Offline
            A Offline
            Andrei Ungureanu
            wrote on last edited by
            #5

            Then, why don't you just query the database, store what you have retrieved in an object, DataSet, List...whatever...and then at the specified interval you just show a value form that object (you can use in this case a counter too). Hope it helps.

            I will use Google before asking dumb questions

            J 1 Reply Last reply
            0
            • A Andrei Ungureanu

              Then, why don't you just query the database, store what you have retrieved in an object, DataSet, List...whatever...and then at the specified interval you just show a value form that object (you can use in this case a counter too). Hope it helps.

              I will use Google before asking dumb questions

              J Offline
              J Offline
              jacklynn_mei
              wrote on last edited by
              #6

              I have done something like the code below But after reading the last data, it encounter error since there is no data persistent while reading. public partial class tempA : Form { SqlDataReader m_Reader; DataSet ds = new DataSet(); private void tempA_Load(object sender, EventArgs e) { string conStrg; conStrg = ("Data Source=DIMENSION3000\\SQLEXPRESS;Initial Catalog=kMasjid;User ID=sa;password=123456"); SqlConnection connTimer = new SqlConnection(conStrg); connTimer.Open(); string selSQL = "Select txtDesc FROM txtScroll"; SqlCommand com = new SqlCommand(selSQL, connTimer); SqlDataAdapter da = new SqlDataAdapter(com); da.Fill(ds, "txtScroll"); m_Reader = com.ExecuteReader(); m_Reader.Read(); Timer myTimer = new Timer(); myTimer.Interval = 5000; myTimer.Enabled = true; myTimer.Start(); myTimer.Tick += new EventHandler(Timer_Tick); } public void Timer_Tick(object sender, EventArgs e) { alphaTxtMain.Text = " " + m_Reader["txtDesc"]; m_Reader.Read() } }

              A 1 Reply Last reply
              0
              • J jacklynn_mei

                I have done something like the code below But after reading the last data, it encounter error since there is no data persistent while reading. public partial class tempA : Form { SqlDataReader m_Reader; DataSet ds = new DataSet(); private void tempA_Load(object sender, EventArgs e) { string conStrg; conStrg = ("Data Source=DIMENSION3000\\SQLEXPRESS;Initial Catalog=kMasjid;User ID=sa;password=123456"); SqlConnection connTimer = new SqlConnection(conStrg); connTimer.Open(); string selSQL = "Select txtDesc FROM txtScroll"; SqlCommand com = new SqlCommand(selSQL, connTimer); SqlDataAdapter da = new SqlDataAdapter(com); da.Fill(ds, "txtScroll"); m_Reader = com.ExecuteReader(); m_Reader.Read(); Timer myTimer = new Timer(); myTimer.Interval = 5000; myTimer.Enabled = true; myTimer.Start(); myTimer.Tick += new EventHandler(Timer_Tick); } public void Timer_Tick(object sender, EventArgs e) { alphaTxtMain.Text = " " + m_Reader["txtDesc"]; m_Reader.Read() } }

                A Offline
                A Offline
                Andrei Ungureanu
                wrote on last edited by
                #7

                public partial class tempA : Form
                {
                SqlDataReader m_Reader;
                DataSet ds = new DataSet();
                int counter = 0;
                private void tempA_Load(object sender, EventArgs e)
                {
                string conStrg;
                conStrg = ("Data Source=DIMENSION3000\\SQLEXPRESS;Initial Catalog=kMasjid;User ID=sa;password=123456");
                SqlConnection connTimer = new SqlConnection(conStrg);
                connTimer.Open();
                string selSQL = "Select txtDesc FROM txtScroll";
                SqlCommand com = new SqlCommand(selSQL, connTimer);
                SqlDataAdapter da = new SqlDataAdapter(com);
                da.Fill(ds, "txtScroll");
                m_Reader = com.ExecuteReader();
                m_Reader.Read();

                Timer myTimer = new Timer();
                myTimer.Interval = 5000;
                myTimer.Enabled = true;
                myTimer.Start();
                myTimer.Tick += new EventHandler(Timer_Tick);
                }
                public void Timer_Tick(object sender, EventArgs e)
                {
                alphaTxtMain.Text = " " + ds.Tables[0].Rows[counter++]["txtDesc"];
                }
                }

                I will use Google before asking dumb questions

                J 1 Reply Last reply
                0
                • A Andrei Ungureanu

                  public partial class tempA : Form
                  {
                  SqlDataReader m_Reader;
                  DataSet ds = new DataSet();
                  int counter = 0;
                  private void tempA_Load(object sender, EventArgs e)
                  {
                  string conStrg;
                  conStrg = ("Data Source=DIMENSION3000\\SQLEXPRESS;Initial Catalog=kMasjid;User ID=sa;password=123456");
                  SqlConnection connTimer = new SqlConnection(conStrg);
                  connTimer.Open();
                  string selSQL = "Select txtDesc FROM txtScroll";
                  SqlCommand com = new SqlCommand(selSQL, connTimer);
                  SqlDataAdapter da = new SqlDataAdapter(com);
                  da.Fill(ds, "txtScroll");
                  m_Reader = com.ExecuteReader();
                  m_Reader.Read();

                  Timer myTimer = new Timer();
                  myTimer.Interval = 5000;
                  myTimer.Enabled = true;
                  myTimer.Start();
                  myTimer.Tick += new EventHandler(Timer_Tick);
                  }
                  public void Timer_Tick(object sender, EventArgs e)
                  {
                  alphaTxtMain.Text = " " + ds.Tables[0].Rows[counter++]["txtDesc"];
                  }
                  }

                  I will use Google before asking dumb questions

                  J Offline
                  J Offline
                  jacklynn_mei
                  wrote on last edited by
                  #8

                  Thanks... But after tried, it wont loop to the first data. After reading the 3rd data, it will error since there is no data on the position 3 (4th data) (my table only have 3 data).

                  A 1 Reply Last reply
                  0
                  • J jacklynn_mei

                    Thanks... But after tried, it wont loop to the first data. After reading the 3rd data, it will error since there is no data on the position 3 (4th data) (my table only have 3 data).

                    A Offline
                    A Offline
                    Andrei Ungureanu
                    wrote on last edited by
                    #9

                    Do we have to do everything for you? Test the counter...if it reaches the end of the DataSet, set it to 0.

                    I will use Google before asking dumb questions

                    J 1 Reply Last reply
                    0
                    • A Andrei Ungureanu

                      Do we have to do everything for you? Test the counter...if it reaches the end of the DataSet, set it to 0.

                      I will use Google before asking dumb questions

                      J Offline
                      J Offline
                      jacklynn_mei
                      wrote on last edited by
                      #10

                      Thank you very much...You've help me a lot... Thank you...

                      A 1 Reply Last reply
                      0
                      • J jacklynn_mei

                        Thank you very much...You've help me a lot... Thank you...

                        A Offline
                        A Offline
                        Andrei Ungureanu
                        wrote on last edited by
                        #11

                        Glad it turned out alright. ;)

                        I will use Google before asking dumb questions

                        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