Hi, shahrul,
Based on my understanding, you want to get therecords from your DataBase and display them one by one with a timer, don't you?
In my point of view, you can get all the records into a DataTable, and display the rows one by one.
For example,
Code Block
DataTable dataTable;
Timer timer;
int index = 0;
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(Properties.Settings.Default.newConnectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from Table1", conn);
dataTable = new DataTable();
adapter.Fill(dataTable); //Get Data from the DataBase, I use an Access as an example
adapter.Dispose();
adapter = null;
conn.Close();
conn = null;
timer = new Timer();
timer.Interval = 30000; //The timer is triggered every 30 seconds
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (index < dataTable.Rows.Count)
{
textBox1.Clear();
foreach (DataColumn column in dataTable.Columns)
{
textBox1.Text += dataTable.Rows[index][column].ToString() + " "; //Show the row in the TextBox
}
index++;
}
else
{
timer.Stop();
}
}
Hi, shahrul,
Based on my understanding, you want to get therecords from your DataBase and display them one by one with a timer, don't you?
In my point of view, you can get all the records into a DataTable, and display the rows one by one.
For example,
Code Block
DataTable dataTable;
Timer timer;
int index = 0;
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(Properties.Settings.Default.newConnectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from Table1", conn);
dataTable = new DataTable();
adapter.Fill(dataTable); //Get Data from the DataBase, I use an Access as an example
adapter.Dispose();
adapter = null;
conn.Close();
conn = null;
timer = new Timer();
timer.Interval = 30000; //The timer is triggered every 30 seconds
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (index < dataTable.Rows.Count)
{
textBox1.Clear();
foreach (DataColumn column in dataTable.Columns)
{
textBox1.Text += dataTable.Rows[index][column].ToString() + " "; //Show the row in the TextBox
}
index++;
}
else
{
timer.Stop();
}
}
hi yu gou, thanks man. your code really works for me.