Implementing Tuples

al4629740
al4629740 used Ask the Experts™
on
I am very new to VB.net.  

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]"

        Try
            Using con As New SqlConnection(GetConnectionString)
                con.Open()

                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

                        'rs.NextResult()
                        While rs.Read
                            lstProfiles.Add(rs.GetString(0))
                        End While
                    End Using
                End Using

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

        Return lstProfiles
    End Function

Open in new window

Comment
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
Commented:
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.

Author

Commented:
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