Displaying data one by one using timer
-
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
-
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
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 -
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
Do you want to do this in a web or desktop application?
I will use Google before asking dumb questions
-
Do you want to do this in a web or desktop application?
I will use Google before asking dumb questions
Winform Application
-
Winform Application
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
-
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
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() } }
-
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() } }
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
-
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
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).
-
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).
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
-
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
Thank you very much...You've help me a lot... Thank you...
-
Thank you very much...You've help me a lot... Thank you...
Glad it turned out alright. ;)
I will use Google before asking dumb questions