如何从DataRow分配值

时间:2013-06-17 09:05:23

标签: c# ado.net datarow

我有以下代码,它将DataSet和currenYear作为参数。该代码应该查看GrowthTarget DataTable,选择符合Select属性条件的行,然后将其分配给foundRows数组。

下一部分只是获取返回行中第二列的值并将其分配给YearGrowthTarget。问题是,当我运行调试模式并在执行此赋值的行上放置一个断点时,“step into”只是简单地退出该方法并且混乱应该显示在主窗体上的数据。 我认为至少返回的YearGrowthTarget应该被执行但是没有,系统就像超人一样继续加载主窗体。

顺便说一句,代码应该在主窗体显示其数据之前运行。 谁能告诉我我做错了什么?

private static int NewYearFreshInstallationGrowthTarget(DataSet ds, int currentYear)
    {
        int YearGrowthTarget = 0;

        DataRow[] foundRows = ds.Tables["GrowthTarget"].Select(
                "GrowthTargetYear = " + currentYear);
        if (foundRows.Length == 0)
        {
            // There are no entries for current year, return 0.
            //TODO: Update statusLabel within original method that called
            //this methos: ComputeNetGrowth method.
        }
        else if (foundRows.Length == 1)
        {
            // There is an entry for current year so return target.
            YearGrowthTarget = (int)(foundRows[0].ItemArray[1]);
        }

        return YearGrowthTarget;
    }

0 个答案:

没有答案