Dear All,
I have a time ticker which updates the time say now for 5 seconds. Then it keep calling a function and in it via sql query based on the current time it shows the relevent sum data. I got few things to confirm am I doing the right method to refresh the chart and secondly I would like to continously show updates on my data based on the live data that is being inserted into my db.
public partial class Form1 : Form
{
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
static int alarmCounter = 1;
static bool exitFlag = false;
// This is the method to run when the timer is raised.
private void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
MySqlConnection localConnection1;
MySqlCommand command;
localConnection1 = new MySqlConnection("Address='******';Database='****';User Name='****';Password='*****';Pooling='false'");
MySqlDataAdapter myLocalDataAdapter1 = new MySqlDataAdapter();
String mySelectQuery1 = "Select " +
"sum(pc) as sumPC" +
"timeStampID " +
"From byteTransmit Where timeStampID='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'";
MessageBox.Show(mySelectQuery1);
MySqlCommand myCommand1 = new MySqlCommand(mySelectQuery1, localConnection1);
DataTable myDataTable1 = new DataTable();
myLocalDataAdapter1.SelectCommand = myCommand1;
myLocalDataAdapter1.Fill(myDataTable1);
chart1.DataSource = myDataTable1;
chart1.DataBind();
chart1.Series["SE"].XValueMember = "timeStampID";
chart1.Series["SE"].YValueMembers = "sumPC";
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
myTimer.Tick += new EventHandler(TimerEventProcessor);
// Sets the timer interval to 5 seconds.
myTimer.Interval = 5000;
myTimer.Start();
}
}
}