Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How can i return more than one value from a function in vb 2008?
The issue i'm having is i'm trying to build a small class that handles connecting and disconnecting from an sql server so that i don't have to worry about it after setting the initial connection properties i'm new to using system.data.sqlclient and vb 2008 basically this is my code:
Public Function ExecuteQuery(ByVal SqlStatement As String) As System.Data.SqlClient.SqlDataReader
Dim DbConnection As New SqlClient.SqlConnection(GetConnectionString)
Dim DbCommand As New SqlClient.SqlCommand(SqlStatement)
Try
DbCommand.Connection = DbConnection
DbConnection.Open()
ExecuteQuery = DbCommand.ExecuteReader()
Catch ex As Exception
Debug.Print(ex.Description)
End Try
DbConnection.Dispose()
DbCommand.Dispose()
End Function
What i want to be able to do is 1. return the SqlDataReader (which i believe ExecuteReader returns) and return any potential errors that may have occured should i just be trying to handle the null reference exception if it occurs (which would indicate a problem of sorts returning the reader) or how can i return the error code as well as the reader?
oh also is it a good idea to be disposing of the dbconnection/command objects as i go or am i better leaving it to clean itself up?
3 Answers
- Anonymous1 decade agoFavorite Answer
Create a helper class with fields to hold the two return parameters. Then return an instance of your class holding the data reader and errors.
Calling Dispose() never hurts.
- TheMadProfessorLv 71 decade ago
While you can only return one value, you could pass the address of whatever else (exception flags, etc.) to the function parameters to be interrogated after return.
- 1 decade ago
you can either create a structure holding these return values and return the structure or return an array of object that holds your return values.
Source(s): my knowledge