你把 select * from tb_hourdata where 时次>='" + a + "' and 时次<='" + b + "'order by 站号 ASC 调试 出来,放到sql server查询下是否有数据
++1 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); } try{ //查询时段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(); }catch(exception e){ } } } 第一步:将sql语句放到sql server中看是否有数据 第二步:对代码进行异常捕获 try{}catch(){} 第三步:断点调试
我把查询语句写成string SqlStr = "select * from tb_hourdata“也没有数据,是 gridview 后面数据填充绑定有问题吗?程序运行没有错误,如果有异常应该提示。运行后web页面为空,什么都没有,看不到gridview.
select * from tb_hourdata where 时次>='" + a + "' and 时次<='" + b + "'order by 站号 ASC
调试 出来,放到sql server查询下是否有数据
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); }
try{
//查询时段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();
}catch(exception e){ }
}
}
第一步:将sql语句放到sql server中看是否有数据
第二步:对代码进行异常捕获 try{}catch(){}
第三步:断点调试
gridview 后面数据填充绑定有问题吗?程序运行没有错误,如果有异常应该提示。运行后web页面为空,什么都没有,看不到gridview.