ImportRow不工作 [英] ImportRow is not working

查看:753
本文介绍了ImportRow不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的例子中,它的返回我2行,而importrow不抛出任何异常,但是当我看到数据表在foreach后的空的,它应该也有2行。

 的foreach(在distinctREFMDossierIds INT refmDossierId)
{
    的DataRow [] =数据行
                    _uc090_WingsIntegrationDataSet.WingsBookingInterface.Select(REFMDossierID =+ refmDossierId);
    如果(datarows.Length大于0)
    {
        的foreach(在数据行的DataRow博士)
        {
            _uc090_WingsIntegrationDataSet.WingsBookingInterface.Clear();
            _uc090_WingsIntegrationDataSet.WingsBookingInterface.ImportRow(DR);
        }
    }    // 2。的foreach主排
    的foreach(在_uc090_WingsIntegrationDataSet.WingsBookingInterface.Rows UC090_WingsIntegrationDataSet.WingsBookingInterfaceRow行)
    {


解决方案

只是一个预感,但也许你正在清理你得到的行集合的表从被引起的DataRow集合处于分离状态的事实?如果是这样的情况下,尝试克隆作出新​​的数据表具有相同的架构,但没有行,然后做导入

 的foreach(在distinctREFMDossierIds INT refmDossierId)
{
    数据表不是Temptable = _uc090_WingsIntegrationDataSet.WingsBookingInterface.Clone();    数据行[] =数据行_uc090_WingsIntegrationDataSet.WingsBookingInterface.Select(REFMDossierID =+ refmDossierId);    如果(datarows.Length大于0)
    {
        的foreach(在数据行的DataRow博士)
        {
            tempTable.ImportRow(DR);
        }
    }    的foreach(在tempTable.Rows UC090_WingsIntegrationDataSet.WingsBookingInterfaceRow行)
    {
        //在这里做你的处理
    }
}

您是当前code将擦桌子的第一个ID后,顺便说一句 - 这可能是有问题的,如果你有你处理多个ID

In the following example, its returning me 2 rows, and the importrow does not throw any exception, but when I see the datatable after the foreach its empty and it should have also 2 rows.

foreach (int refmDossierId in distinctREFMDossierIds)
{
    DataRow[] datarows =
                    _uc090_WingsIntegrationDataSet.WingsBookingInterface.Select("REFMDossierID =" + refmDossierId);
    if(datarows.Length>0)
    {
        foreach(DataRow dr in datarows)
        {
            _uc090_WingsIntegrationDataSet.WingsBookingInterface.Clear();
            _uc090_WingsIntegrationDataSet.WingsBookingInterface.ImportRow(dr);
        }
    }

    //2.     foreach master row
    foreach (UC090_WingsIntegrationDataSet.WingsBookingInterfaceRow row in _uc090_WingsIntegrationDataSet.WingsBookingInterface.Rows)
    {

解决方案

Just a hunch, but maybe the fact that you're clearing the table you got the collection of rows from is causing the DataRow collection to be in a detached state? If that's the case, try Clone to make a new DataTable that has the same schema, but no rows, and then do the Import:

foreach (int refmDossierId in distinctREFMDossierIds)
{
    DataTable tempTable = _uc090_WingsIntegrationDataSet.WingsBookingInterface.Clone();

    DataRows[] datarows = _uc090_WingsIntegrationDataSet.WingsBookingInterface.Select("REFMDossierID = " + refmDossierId);

    if (datarows.Length > 0)
    {
        foreach(DataRow dr in datarows)
        {
            tempTable.ImportRow(dr);
        }
    }

    foreach (UC090_WingsIntegrationDataSet.WingsBookingInterfaceRow row in tempTable.Rows)
    {
        //  Do your processing here
    }
}

You're current code will wipe the table after the first ID, by the way - which could be problematic if you have more than one ID you're dealing with.

这篇关于ImportRow不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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