日期:2014-05-17 浏览次数:20398 次
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class 子页面_1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DateTime currentTime,a,b;//a和b为起止时间 currentTime = System.DateTime.Now; if (System.DateTime.Now.Hour >= 20) { a = currentTime.Date.AddHours(-3); b = a.AddHours(23); } else { a = currentTime.Date.AddHours(-27); b = currentTime.Date.AddHours(-4); } //查询时段a-b的数据 string ConStr = "server=IBM;user id=sa;pwd=sa;database=dataserver"; SqlConnection con = new SqlConnection(ConStr); string SqlStr = "select * from tb_hourdata where 时次>='" + a + "' and 时次<='" + b + "'order by 站号 ASC"; con.Open(); SqlDataAdapter da = new SqlDataAdapter(SqlStr, con); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); } }