How to pass strongly-typed datasets to a function and back

I want to get information from a database about a file.  I have an app that uses a strongly-typed DataSet created by Visual Studio 2005 (  This creates a TableAdapter and DataTable.  I would like to pass the TableAdapter and DataTable to a function and then return the TableAdapter and DataTable.  Perhaps I need to pass the whole dataset.  In any case, I can't find how to pass these back and forth.  Can you help?

I pick the TableAdapter and DataTable as shown below.  This works fine, except I can't see how I would pass this back and forth to a function.  Right now it's in my main presentation web page, and I want it to be in a separate class, like a data access layer.
If strLocation = "k" Then   
            If URL.IndexOf("") <> -1 
                DocAdapter = New DocumentsDEVTableAdapters.DocumentsDEV_TableAdapter
                CurrentDT = New DocumentsDEV.DocumentsDEV_DataTableDataTable
            Else    'For Production and localhost:
                DocAdapter = New DocumentsPRODTableAdapters.DocumentsPROD_TableAdapter
                CurrentDT = New DocumentsPROD.DocumentsPROD_DataTableDataTable
            End If
        ElseIf strLocation = "h" 
            If GlobalVars.ReferringURL.IndexOf("") <> -1
                DocAdapter = New companyExtensionsDEVTableAdapters.companyExtensionsDEV_TableAdapter
                CurrentDT = New companyExtensionsDEV.companyExtensionsDEV_DataTableDataTable
            Else    'For Prod and localhost:
                DocAdapter = New companyExtensionsProdTableAdapters.companyExtensionsPROD_TableAdapter
                CurrentDT = New companyExtensionsProd.companyExtensionsPROD_DataTableDataTable
            End If
        End If
        CurrentDT = DocAdapter.GetFileName(strDocumentNumber)

Open in new window

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

YiogiConnect With a Mentor Commented:
I don't see where the problem is. Just passing the variables byref should suffice. It shouldn't matter if you pass a strongly typed object or whatever else.
psmithphilAuthor Commented:
What you say sounds like what I need to do.  I'm trying to picture how you would have me set this up.  Would it look like I have here? (you can see I also don't know how I would set the datatype when I dimension DocAdapter & CurrentDT.
Dim DocAdapter
Dim CurrentDT
Dim DataSetMaker As DataSetProcessor
DataSetMaker = New DataSetProcessor
DataSetMaker.TestTheDataSet(DocAdapter, CurrentDT)
Public Class DataSetProcessor
    Public Sub TestTheDataSet(ByRef DocAdapter, ByRef CurrentDT)
        If strLocation = "k" Then
            If URL.IndexOf("") <> -1 Then
                DocAdapter = New DocumentsDEVTableAdapters.DocumentsDEV_TableAdapter
                CurrentDT = New DocumentsDEV.DocumentsDEV_DataTableDataTable
        etcetera, etcetera . . .
    End Sub
End Class

Open in new window

Assuming you have a custom adapter of your own then you'd set the datatypes as:
Dim DocAdapter As DocumentsDEVTableAdapters.DocumentsDEV_TableAdapter
Dim CurrentDT As DocumentsDEVDataSet.DocumentsDEV_DataTableDataTable

One mistake you are making is the data table. You are supposed to select the datatable somehow from your adapter, thats the purpose of having an adapter anyway.
It should be something like:
CurrentDT = DocAdapter .GetDataWithSomeMethodYouDefinedInYourAdapter("CriteriaToReturnData")

Passing the strong datatypes into a function is just the same as passing any other variable. If you want to try reading the following article. It explains pretty well how to create and use custom data adapters.
psmithphilAuthor Commented:
Thank you, Yiogi!   This was an excellent answer.  What you provided will make life a lot easier.
All Courses

From novice to tech pro — start learning today.