gpt4 book ai didi

asp.net - 如何处理 'The source contains no DataRows. ' 错误

转载 作者:行者123 更新时间:2023-12-02 03:27:48 37 4
gpt4 key购买 nike

请找到下面的代码。如果行为空,它将通过错误“源不包含数据行”。如何处理这个??

if (dtTemSec.Rows.Count > 0)
{
grdStepDetails.DataSource = dtTemSec.AsEnumerable()
.Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder)
.CopyToDataTable();
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
else
{
grdStepDetails.DataSource = null;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}

最佳答案

像这样使用:-

 if (dtTemSec.Rows.Count > 0)
{
var table = dtTemSec;
var rows = table.AsEnumerable().Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder);
var dt = rows.Any() ? rows.CopyToDataTable() : table.Clone();
grdStepDetails.DataSource = dt;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
else
{
grdStepDetails.DataSource = null;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}

关于asp.net - 如何处理 'The source contains no DataRows. ' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29366065/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com