HelpASisterOut
HelpASisterOut

Reputation: 3185

Why can't I return a Dataset from a function inside a VB.net class?

I am using WinForms and trying to retrieve all the data from the database once on form Load so I won't have to go back and forth to the database a lot.

I created a class and wrote a function that returns a dataset but I'm not being able to refer to it from my forms.

This is the code:

Private Function FillKeywords() As DataSet
    Dim ds1 As DataSet : Dim cmd as SqlCommand
    Dim da As SqlDataAdapter
    Try
        cmd = New SqlCommand("Dbo.selectkeywords", cn)
        cmd.CommandType = CommandType.StoredProcedure
        da = New SqlDataAdapter(cmd)
        ds1 = New DataSet
        da.Fill(ds1, "Keywords")
        Return ds1
    Catch ex As SqlClient.SqlException
        WriteExToFile(ex.ToString)
    Catch ex As Exception
        WriteExToFile(ex.ToString)
    End Try
End Function

Upvotes: 0

Views: 2616

Answers (1)

nvoigt
nvoigt

Reputation: 77364

I'll take a wild guess and say you will need to lose the Private keyword if you want your function to be accessible from another class or module.

Upvotes: 3

Related Questions