TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sean Blackmon
NA
5
2k
How can I select certain data in a database to place in gridview?
Jun 17 2011 8:19 PM
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
Reply
Answers (
5
)
Pivot Table Drilldown Formatting
A Bug Related To Form Constructor