[英]Add range rows from one DataTable to another
有一个数据表,我需要创建另一个具有第一个行子集范围的数据表。 所以我希望第二个 DataTable 从第一个行开始直到 n + y 行。 请问我该怎么做?
DataTable limitData = new DataTable();
for (int rowIndex = startingRow; rowIndex < endingRow; rowIndex++)
{
limitData.Rows.Add(columnarData.Rows[rowIndex].ItemArray);
}
给出错误:“输入数组比此表中的列数长。”
代码在 C# .NET 4.0 中
试试这个,让我知道这是否有效
DataTable limitData =limitData.Clone();
for (int rowIndex = startingRow; rowIndex < endingRow; rowIndex++)
{
limitData.Rows.Add(columnarData.Rows[rowIndex].ItemArray);
}
要么
DataTable limitData =limitData.Clone();
foreach (DataRow dr in columnarData.Rows)
{
limitData.Rows.Add(dr);
}
试试这个
for (DataRow r in dt.Rows)
{
if(some condition))
{
extractedData.ImportRow(r);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.