Ok I'm new to coding and am trying to figure out how I can code in Visual Studio C#. I have a database table that has 3 columns and 10 rows. The column headings are Status, ID, and EmployeeName. In the Status colum, each row has a single digit from #1 to #4. What I want to do is utilize a timer to check this table every 60 seconds and return any row and column where the status ID is greater than 1. Here is what I have so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Data.SqlClient;
using System.Timers;
using System.ComponentModel;




public partial class Poll : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    public Poll()
    {
        InitializeComponent();
        timer.Interval = 60000;
        timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    }
    private void InitializeComponent()
    {
      
    }

    System.Timers.Timer timer = new System.Timers.Timer();
    DataTable dt = new DataTable();
    void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        using (OleDbConnection con = new OleDbConnection("MAS2000"))
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter("Insert * from SensorEvent", con);
            adapter.Fill(dt);

            DataRow[] rows = dt.Select("StatusID > '1'");
            DataTable temp = new DataTable();
            temp.Columns.Add("StatusId", typeof(int));
            temp.Columns.Add("SensorID", typeof(String));
            temp.Columns.Add("UserID", typeof(String));

            //add columns to temp

            foreach (DataRow r in rows)
            {
                //add rows to temp as follows
                temp.Rows.Add(int.Parse(r[0].ToString()), r[1].ToString(), r[2].ToString());

            }

            this.dataGrid.DataSource = temp;

It brings up the tables but the function of how to only import the desired results(status id that is higher than 1) does not work. I get the whole table. So any help with this would be very much appreciated. Thanks

You need to use SELECT statement. (SELECT * FROM SensorEvent)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.