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
The Global Values
The Function I call
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
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)
Code:
Public ProgramName As String = " "
Public ProjectType As String = " "
Public SqlProjectType As Integer
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
Thanks,
-NJ