public string getReportHTML(_TableProperty tableProperty, Stream stream)
{
string sql = "select ";
string columnAdd="<table><tr><td>";
foreach (var column in tableProperty.Columns)//nullreferencepointexception
{
sql += column.Key + " as [" + column.Value + "],";
columnAdd += "<th> column.Value </th>";
}
columnAdd += "</table></tr></td>";
sql=sql.TrimEnd(',');
sql += " from" + tableProperty.ReportTable;
sql = sql + " where 1=1 " + (string.IsNullOrEmpty(tableProperty.ReportCondition) ? "" : "and " + tableProperty.ReportCondition);
SqlConnection _con = new SqlConnection(@"server=mausam-pc\sqlexpress;uid=***;pwd=***;initial catalog=HRMSN");
SqlCommand _cmd = new SqlCommand(sql, _con);
_con.Open();
SqlDataReader _reader = _cmd.ExecuteReader();
while (_reader.Read())
{
foreach (var column in tableProperty.Columns)
{
columnAdd += _reader.GetOrdinal(column.Value);
}
}
columnAdd += "</table></tr></td>";
string htmlread = "<html><title>General</title><body> columnAdd </body></html>";
if (_reader != null)
{
_reader.Close();
}
_con.Close();
return htmlread;
}
请告诉我如何删除空点异常或如何在列的情况下为 foreach 循环使用 new 关键字。它是一个 dll 库类,用于呈现 HTML 页面,以显示字典调用的任何特定表。