当找不到行时,使用CopyToDataTable()避免异常 我没有找到任何行时尝试了这段代码然后它给了我错误源不包含DataRows。
ds.Tables.Add(dsDecEjID.Tables(0).Select(Cond).CopyToDataTable())
答案 0 :(得分:3)
您没有指定错误,但我猜测select语句返回null。你不能使用简单的空检查吗?
var table = dsDecEjID.Tables(0).Select(Cond);
if(table != null)
ds.Tables.Add(table.CopyToDataTable());
答案 1 :(得分:2)
table != null
没有工作,也许像我这样的人,我的决心是
var tableOb = tableMySqlSerialConn.Select(stringSelect);
if (tableOb.Count()>0)
{
tempTable =tableOb.CopyToDataTable();
}
答案 2 :(得分:0)
检查表格中是否有任何行:
If dsDecEjID.Tables(0).Rows.Count > 0 Then
ds.Tables.Add(dsDecEjID.Tables(0).Select(Cond).CopyToDataTable())
End If
答案 3 :(得分:0)
如果您使用的是C#6.0,则可以使用:
table?.CopyToDataTable()