播种DataTable.Rows.Add() [英] Seed up DataTable.Rows.Add()

查看:191
本文介绍了播种DataTable.Rows.Add()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!是否可以加快addRow方法?

thx !!!!

Hi! it is possible, to speed up the addRow-method?

thx!!!!

foreach (TableCell cell in sourcheTable.Rows[0].Cells)
{
    dt.Columns.Add(cell.Name);
}

foreach (TableRow Row in sourcheTable.Rows)
{
    System.Data.DataRow row;
    row = dt.NewRow();
    foreach (TableCell item in Row.Cells)
    {
        if (dt.Columns.Contains(item.Name))
        {
            row[item.Name] = item.Value;
        }
        else
        {
            dt.Columns.Add(item.Name);
            row[item.Name] = item.Value;
        }
    }
    dt.Rows.Add(row);
}

推荐答案

这里最明显的一点是,您必须执行Columns.每行都包含测试-您确实不需要通过第一行后,请执行此操作.由于您已经是第一轮了,所以您无需重做此测试.
The most obvious point here is that you have to perform the Columns.Contains test on every row - you really shouldn''t need to do it once you''ve passed the first line. As you''ve already populated this the first time round, then you don''t need to redo this test.


这篇关于播种DataTable.Rows.Add()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆