1

未找到行时使用 CopyToDataTable() 避免异常我在未找到行时尝试了此代码,然后它给了我错误源不包含 DataRows。

ds.Tables.Add(dsDecEjID.Tables(0).Select(Cond).CopyToDataTable())
4

4 回答 4

3

您没有指定错误,但我猜 select 语句返回 null。你不能使用简单的空检查吗?

var table = dsDecEjID.Tables(0).Select(Cond);
if(table != null)
    ds.Tables.Add(table.CopyToDataTable());
于 2013-08-06T13:38:16.263 回答
2

table != null不工作我,也许像我这样的人,我的解决办法是

var tableOb = tableMySqlSerialConn.Select(stringSelect);
if (tableOb.Count()>0)
{
tempTable =tableOb.CopyToDataTable();
}
于 2015-08-07T12:44:10.650 回答
0

检查表中是否有任何行:

If dsDecEjID.Tables(0).Rows.Count > 0 Then
    ds.Tables.Add(dsDecEjID.Tables(0).Select(Cond).CopyToDataTable())
End If
于 2013-08-06T13:38:59.033 回答
0

如果您使用的是 C# 6.0,那么您可以使用:

table?.CopyToDataTable()
于 2019-05-29T14:24:38.950 回答