Implementing Tuples

al4629740 used Ask the Experts™
I am very new to  

In the following code I am trying to implement tuples.  You'll notice in the SQL clause that I pulled [System Name] and Agency ID and I want them to appear as AgencyID &  "-" & [System Name]  in a dropdown list.  I'm figuring that I will use tuples in lstProfiles in order to create the list.  What changes do I need to make in order to make that happen?

 Public Function fetchActiveProfiles() As List(Of String)
        Dim lstProfiles As New List(Of String)

        Dim sqlCmd As String
        sqlCmd = ""
        sqlCmd = sqlCmd & " select [System Name],AgencyID"
        sqlCmd = sqlCmd & " from tblOrgProfile"
        sqlCmd = sqlCmd & " Where Active = 1"
        sqlCmd = sqlCmd & " order by [System Name]"

            Using con As New SqlConnection(GetConnectionString)

                Using cmd As New SqlCommand(sqlCmd, con)
                    cmd.CommandType = CommandType.Text

                    Using rs As SqlDataReader = cmd.ExecuteReader()
                        If Not rs.HasRows Then
                            Return lstProfiles
                        End If

                        While rs.Read
                        End While
                    End Using
                End Using

            End Using
        Catch ex As Exception
            Throw New DatabaseConnectionException()
        End Try

        Return lstProfiles
    End Function

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
EE Topic Advisor
Most Valuable Expert 2014
Awarded 2013
Concatenate in a SQL Server T-SQL query uses a plus symbol, but also note that if any column isn't a string, that has to be cast to varchar first.

T-SQL specific
        sqlCmd = sqlCmd & " select [System Name],AgencyID, AgencyID + '-' +  [System Name]"
        sqlCmd = sqlCmd & " select [System Name],AgencyID, cast(AgencyID as varchar) + '-' +  [System Name]"

reasonably generic
        sqlCmd = sqlCmd & " select [System Name],AgencyID, concat(AgencyID, [System Name])" -- does the type conversion for you

The SQL standard concatenation symbol is || but quoting a column name [using brackets] isn't standard either.


Very good solution and that works well.  The purpose of me asking how to do this using tuples was mainly for learning purposes so if its possible for an expert to provide how I might do that using .NET that would be most helpful.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial