克隆的数据行始终为空

时间:2013-12-03 14:35:06

标签: c# datatable

我正在使用此函数将数据表拆分为较小的数据表,并且克隆的行始终为空,为什么?

public static List<DataTable> SplitDataTable(DataTable originalTable, int batchSize)
{
    List<DataTable> partitions = new List<DataTable>(); 
    int i=0;
    foreach (DataRow row in originalTable.Rows)
    {
        int cell = i / batchSize;
        if (partitions.Count < cell+1 ||  partitions[cell] == null)
        {
            partitions.Add( new DataTable());
        }
        partitions[cell].ImportRow(row);                
        i++;
    }
    return partitions;
}

1 个答案:

答案 0 :(得分:0)

documentation for the ImportRow() metho d,这两个摘录对我来说很突出:

  

如果作为参数传递的DataRow处于分离状态,则会被忽略,并且不会抛出任何异常。

  

如果新行违反约束,则不会将其添加到数据表中。

相关问题