string tableName = RadioButtonList1.SelectedValue;
string view = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
string[] sqlstr = new string[2];
sqlstr[0] = "select top 1 * from z_" + tableName + " where dataday between cast((convert(varchar(10),dateadd(day,0,'" + view + "'),120) + ' 1:00') as datetime) and cast((convert(varchar(10),'" + view + "',120) + ' 1:59') as datetime) order by dataday ASC";
sqlstr[1] = "select top 1 * from z_" + tableName + " where dataday between cast((convert(varchar(10),dateadd(day,0,'" + view + "'),120) + ' 2:00') as datetime) and cast((convert(varchar(10),'" + view + "',120) + ' 2:59') as datetime) order by dataday ASC";
conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["key"]);
conn.Open();
for (int i = 0; i < 2; i++)
{
SqlDataAdapter p = new SqlDataAdapter(sqlstr[i], conn);
DataSet ds = new DataSet();
p.Fill(ds);
string G = "GridView" + i.ToString();
GridView dv = this.form1.FindControl(G) as GridView;
dv.DataSource = ds;
dv.DataBind();
}
conn.Close();
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 33: string G = "GridView" + i.ToString();
行 34: GridView dv = this.form1.FindControl(G) as GridView;
行 35: dv.DataSource = ds;
行 36: dv.DataBind();
行 37: conn.Close();
|
源文件: c:\Inetpub\wwwroot\water\e_day.aspx.cs 行: 35