C#中DataTable判断是否存在某列
程序员文章站
2022-03-04 12:34:27
...
dt.Columns.Contains("列名")
例如:
if (dt.Columns.Contains("噪音数据")) {
columns.Add(new ExportFieldParam("传感器", "传感器", 300));
columns.Add(new ExportFieldParam("时间", "时间", 150));
columns.Add(new ExportFieldParam("值", "值", 40));
columns.Add(new ExportFieldParam("单位", "单位", 40));
columns.Add(new ExportFieldParam("噪音数据", "噪音数据", 60));
}
else
{
columns.Add(new ExportFieldParam("传感器", "传感器", 300));
columns.Add(new ExportFieldParam("时间", "时间", 150));
columns.Add(new ExportFieldParam("值", "值", 40));
columns.Add(new ExportFieldParam("单位", "单位", 40));
}