问题描述
好吧,我是编码的新手,正在尝试弄清楚如何在Visual Studio C#中进行编码.我有一个数据库表,该表具有3列和10行.列标题为状态","ID"和"EmployeeName".在状态"列中,每行从#1到#4都有一位数字.我想做的是利用计时器每60秒检查一次此表,并返回状态ID大于1的任何行和列.这是我到目前为止的内容:
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 column, 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;
它显示了表格,但是如何仅导入所需结果(状态ID大于1)的功能不起作用.我得到整张桌子.因此,对此的任何帮助将不胜感激.
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
推荐答案
这篇关于我如何从数据库中选择数据以显示在gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!