source 在使用 take asp.net 时没有数据行
source cantain no data row while using take asp.net
当前,当记录为零时,我收到错误 source
无法管理数据行 我已经检查过它 count>0 但仍然
我想知道如何解决这个问题。
dynamic dt = ds.Tables(0);
int totalrowCount = dt.Rows.Count;
//dt.Rows.Count
//dt.Select().Take(100)
// dt.Rows.Cast(Of System.Data.DataRow)().Take(100)
DataTable dt1 = default(DataTable);
if (totalrowCount > 0) {
dt1 = dt.AsEnumerable().Take(100).CopyToDataTable();
} else {
dt1 = dt.AsEnumerable().CopyToDataTable();
}
使用以下内容检查行数;
if (ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
但是当行号<=0时
dt1 = dt.AsEnumerable().CopyToDataTable();
这一行没有意义。
您需要获取空行吗?
由于 documented,CopyToDataTable()
无法在空的行序列上调用 - 大概是因为没有要包含的架构信息。相反,如果您知道原来的 table 是空的并且您想要一个具有相同模式的新 table,只需克隆它即可。所以你会:
DataTable dt = ds.Tables(0);
DataTable newTable = dt.Rows.Count > 0
? dt.AsEnumerable().Take(100).CopyToDataTable()
: dt.Clone();
当前,当记录为零时,我收到错误 source 无法管理数据行 我已经检查过它 count>0 但仍然 我想知道如何解决这个问题。
dynamic dt = ds.Tables(0);
int totalrowCount = dt.Rows.Count;
//dt.Rows.Count
//dt.Select().Take(100)
// dt.Rows.Cast(Of System.Data.DataRow)().Take(100)
DataTable dt1 = default(DataTable);
if (totalrowCount > 0) {
dt1 = dt.AsEnumerable().Take(100).CopyToDataTable();
} else {
dt1 = dt.AsEnumerable().CopyToDataTable();
}
使用以下内容检查行数;
if (ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
但是当行号<=0时
dt1 = dt.AsEnumerable().CopyToDataTable();
这一行没有意义。 您需要获取空行吗?
由于 documented,CopyToDataTable()
无法在空的行序列上调用 - 大概是因为没有要包含的架构信息。相反,如果您知道原来的 table 是空的并且您想要一个具有相同模式的新 table,只需克隆它即可。所以你会:
DataTable dt = ds.Tables(0);
DataTable newTable = dt.Rows.Count > 0
? dt.AsEnumerable().Take(100).CopyToDataTable()
: dt.Clone();