We help IT Professionals succeed at work.
Get Started

Referencing a DataSet from a function

nkewney
nkewney asked
on
257 Views
Last Modified: 2010-04-23
I have a function like the one below which returns a dataset.

I want to (in another function) loop through each result, perform a calculation sort at the end these calculations.

How do I reference the fields of the dataset individually within another function?

Here's my function...

    Public Function GetUserPostcodes() As DataSet

        Dim pcConnection As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;Database=live;User Id=sa;Password=Unv06rsL;")

        Dim pcCommand As New System.Data.SqlClient.SqlCommand("SELECT People.Person_Postcode, People.Person_nameFirst, People.Person_nameLast FROM People INNER JOIN UserList ON People.Person_ID = UserList.Person_ID INNER JOIN UserCompany ON UserList.User_Username = UserCompany.Username WHERE (UserCompany.Company_ID = '" & Session("userlist_default_company") & "')", pcConnection)

        pcConnection.Open()

        Dim pcDataAdapter As New System.Data.SqlClient.SqlDataAdapter()

        pcDataAdapter.SelectCommand = pcCommand

        Dim pcDataSet As New DataSet()
        pcDataAdapter.Fill(pcDataSet)
        pcConnection.Close()

        'Return the DataSet
        Return pcDataSet

    End Function
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE