通过TableAdapter迭代(循环)

时间:2013-01-30 17:28:32

标签: vb.net iteration strongly-typed-dataset tableadapter strong-typing

我们希望遍历TableAdapter并从名为ClassName的特定列中提取TableAdapter中每行的值。我们稍后会添加其他列。

我们使用DataSet设计器创建了以下内容:

DataSet Name:      DataSetSchedules
DataTable Name:    DataTableSchedules
TableAdapter Name: DataTableDataAdapterSchedules

TableAdapter的设置如下:

Dim theTableAdapter As New DataSetSchedulesTableAdapters.DataTableTableAdapterSchedules

最初填充如下:

Private Sub TeacherSchedules_Init(sender As Object, e As EventArgs) Handles Me.Init

    ' Load the data from the database into the GridView.
    '---------------------------------------------------
    GridViewSummary.DataSource = theTableAdapter.GetDataByAll(TextBoxSearch.Text)
    GridViewSummary.DataBind()

End Sub

我们想利用已经创建的TableAdapter,这就是我们想要遍历TableAdapter的原因。

我们将使用它来创建一个列表,该列表将作为电子邮件的一部分显示。

您能告诉我填充和循环现有TableAdapter需要哪些编码来从ClassName数据列中提取值吗?

我认为应该是这样的:

    Dim strClassName As String = ""
    Dim objAadapter As New DataSetSchedulesTableAdapters.DataTableTableAdapterSchedules
    Dim objDataTable As <What to I put here?> = objAadapter.GetDataByAll(TextBoxSearch)

    For Each row As <What to I put here?> In objDataTable
        strClassName = row.ClassName
    Next

但我不知道应该用什么代替角度支架(&lt;&gt;)

1 个答案:

答案 0 :(得分:1)

Friend Function ValidateUserCode(ByVal ScannedUserCode) As Boolean
    Try
        Dim taOperator As New dsBusinessTableAdapters.GetOperatorTableAdapter, isUpdated As Boolean = True
        If taOperator.GetData().Count <> My.Settings.Zero Then
            For Each dr As DataRow In taOperator.GetData()
                Dim dbUserCode As String = dr.Item(1).ToString 'pass usercode index to readable variable
                If ScannedUserCode = dbUserCode Then ' UserCode EXISTS in database?
                    If GetOperatorDetails(dr) = isUpdated Then Return True 'YES,Get their Details and lets go!
                End If
            Next
            Return False
        Else : Return False 'for now...'show ADD NEW OPERATOR FORM? 'or have a default Admin Operator...
        End If
    Catch ex As Exception
        Return False
    End Try
End Function