Question Referencing a dataset in a class

dsk96m

Well-known member
Joined
Jan 11, 2013
Messages
173
Programming Experience
1-3
So I have a form that has controls and binding sources, etc
VB.NET:
Public Class frm_newflightcard
....
end class

in the same form code, I added a class:
VB.NET:
Public Class DropDownListHelper
    Public Shared Function GetDropDownList(path As String) As List(Of String)
        Dim result As New List(Of String)()

        [B]???????[/B]

        For Each row As DataRow In table.Rows
            result.Add((row("name")).ToString())
        Next
        Return result
    End Function
End Class

It is in this class I am having an issue. I can not figure out how to get the data from the dataset. The dataset is called ftappdataset. I want to pull the data from the fcdt datatable in that dataset so I can iterate through its rows. Everything I try comes back with a row count of 0 when I know for sure it isnt 0. I know in the form class it works because there are binding sources and table adapters, etc, but I cant figure out how to do it in this separate class. Please help.
 
I tried
Dim ds As DataSet = Flight_Test_App.FlightTestApp2DataSet
but get 'FlightTestApp2DataSet' is a type in 'Flight_Test_App' and cannot be used as an expression
 
Ended up doing this, not sure if it is correct though
Dim ta As New FlightTestApp2DataSetTableAdapters.flightcardTableAdapter
Dim table As New FlightTestApp2DataSet.flightcardDataTable
ta.Fill(table)
 
That code is obviously creating new objects in your class instance. If you want to use objects that already exist in the form then that's not going to achieve it. The form would have to pass those objects to the class instance, which it would do the same way you usually pass data around: by setting a field or property or calling a method and passing an argument. It's up to you to define the appropriate fields/properties/methods in your class.
 
Back
Top