列表“ GetEnumerator”中的foreach数据表错误

时间:2019-02-28 22:32:35

标签: c# asp.net

我在第二个foreach循环中遇到此错误,对我来说逻辑似乎很好..:

(foreach语句无法对'datatable'类型的变量进行操作,因为'datatable'不包含'GetEnumerator'的公共实例定义)

foreach (DataTable testdatatable in test)
                    {
                        foreach (DataRow datarow in testdatatable)
                        {
                            string value = datarow.Field<string>("Slave_IO_Running");   //Looks for "Slave_IO_Running" status.

                            if (value == "Yes")
                            {
                                results.Add(siteName + ": WORKING"); //adds working to the visual table 
                            }
                            else
                            {
                                results.Add(siteName + ": REPLICATION ERROR"); //adds not working to the result list
                            }
                            break;
                        }
                    }

1 个答案:

答案 0 :(得分:2)

迭代DataTable.Rows属性:

 foreach (DataRow datarow in testdatatable.Rows)