vb.net 循环遍历强类型数据集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14606475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:06:30  来源:igfitidea点击:

Looping through a strongly typed DataSet

vb.netdatatabledatasetstrongly-typed-dataset

提问by Emad-ud-deen

How do you loop through a strongly typed DataSet?

如何遍历强类型数据集?

We have the following defined in the DataSet designer:

我们在数据集设计器中定义了以下内容:

DataSet name:      DataSetSchedules
DataTable name:    DataTableSchedules
TableAdapter name: DataTableDataAdapterSchedules

This is a code sample I found using Google:

这是我使用 Google 找到的代码示例:

Dim col As DataColumn
Dim dt as DataTable
Dim dr as DataRow
Dim strMyValue AS String = ""

dt = ds.Tables(0)

For Each dr In dt.Rows
   For Each col In dt.Columns
    StrMyValue = dr(col.ColumnName)
   Next
Next

Since a DataSet was already created in the DataSet desiner, I tried this:

由于已经在 DataSet desiner 中创建了 DataSet,我尝试了以下操作:

Dim col As DataColumn
Dim dt as DataTable
Dim dr as DataRow
Dim strMyValue AS String = ""

dt = DataSetSchedules.Tables(0)

Intellisence told me that "Tables" was not a choice so I'm stuck.

Intellisence 告诉我“表格”不是一个选择,所以我被卡住了。

Most of the code samples I found show that this is how to do it, but I don't think that this applies to strongly typed DataSets.

我发现的大多数代码示例都表明这是如何做到的,但我认为这不适用于强类型数据集。

Can you show the correct coding needed to loop through DataSetSchedules and get the value in dr(col.ColumnName)?

您能否显示遍历 DataSetSchedules 并获取 dr(col.ColumnName) 中的值所需的正确编码?

采纳答案by Abdusalam Ben Haj

Try This :

尝试这个 :

 Dim DS as new DataSetSchedules

    DT = DS.Tables(0)

 For Each DR as DataRow In DT.Rows
   ' Code
 Next

or as @Tim Suggested use the strongly typed Tables. see MSDN

或作为@Tim 建议使用强类型表。见MSDN

A typed DataSet is a class that derives from a DataSet. As such, it inherits all the methods, events, and properties of a DataSet. Additionally, a typed DataSet provides strongly typed methods, events, and properties. This means you can access tables and columns by name, instead of using collection-based methods

类型化数据集是派生自数据集的类。因此,它继承了 DataSet 的所有方法、事件和属性。此外,类型化数据集提供强类型化方法、事件和属性。这意味着您可以按名称访问表和列,而不是使用基于集合的方法