Quantcast
Viewing all articles
Browse latest Browse all 27039

[RESOLVED] Help Please - How to return multiple values from a called Function

Hello All,

I have a Function that I call to query a SQL Table for certain columns. I need to return the value of two columns after the call. I am not having any success other than setting global strings with the SQL Column results and I was hoping there is an easier way.

Here is what I'm doing and why I would like it to do.

How I call the Function
Code:

Dim NewSQLQuery As new GetProjectData
Dim ReturnedData as NewSQLQuery.SearchProjectTable(ProjectId)

The Global Values

Code:

        Public ProgramName As String = " "
        Public ProjectType As String = " "
        Public SqlProjectType As Integer

The Function I call

Code:

        Try
            MySQLconnection = New SqlConnection(Myconstring)
            MySQLconnection.Open()

            mySQLCom = "Select * from Projects where Project_id='" + ProjectID + "'"

            MySQLcommand = New SqlCommand(mySQLCom, MySQLconnection)

            If ConnectionState.Open Then
                MySQLreader = MySQLcommand.ExecuteReader()
            End If

        Catch ex As SqlException
            MessageBox.Show("Error while Reading a record from the database - " & ex.Message, " - Read Project Table")
            Return "Read Error"
            Exit Function
        End Try

        If MySQLreader.HasRows Then
            MySQLreader.Read()
            SqlProjectType = MySQLreader.GetInt32(2)
            ProjectType = Convert.ToString(SqlProjectType)
            ProgramName = MySQLreader(4)
            Return "Data Found"
        Else
            MessageBox.Show("Invalid Project/Program Name!!")
            Return "Data Not Found"
        End If

What I would like to do to avoid using the Global variables. Is there a way to call the Function and have it return multiple Variables of Data instead of just one?

Thanks,

-NJ

Viewing all articles
Browse latest Browse all 27039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>