Avatar of spen_lang
spen_lang

asked on 

VB Net - Sort a Multi List that Contains Duplicates

Hi,

I need add 6 values (3 rows) to a list and then sort the list by the datetime value. However, this value is not unique. I am then outputting the list to a string.

The following works well until I have duplicate values. How can I change the following to allow duplicates?

This is code that I am adding to a Reporting Services report.

Thanks, Greg

    Friend Function GetStatusHistory(sStatus1 As String, dtStatusTime1 As Nullable(Of DateTime), sStatus2 As String, dtStatusTime2 As Nullable(Of DateTime), sStatus3 As String, dtStatusTime3 As Nullable(Of DateTime)) As String

        Dim sResult As String = ""
        Dim lstStatus As New System.Collections.Generic.SortedList(Of DateTime, String)

        If Not IsNothing(dtStatusTime1) Then
            lstStatus.Add(dtStatusTime1, sStatus1)
        End If

        If Not IsNothing(dtStatusTime2) Then
            lstStatus.Add(dtStatusTime2, sStatus2)
        End If

        If Not IsNothing(dtStatusTime3) Then
            lstStatus.Add(dtStatusTime3, sStatus3)
        End If

        For Each pair As System.Collections.Generic.KeyValuePair(Of DateTime, String) In lstStatus
            If String.IsNullOrEmpty(sResult) Then
                sResult = pair.Value + " @ " + pair.Key.ToString("dd/MM/yy HH:mm")
            Else
                sResult = sResult + ", " + pair.Value + " @ " + pair.Key.ToString("dd/MM/yy HH:mm")
            End If
        Next

        Return sResult

    End Function

Open in new window

Visual Basic.NETVB Script.NET ProgrammingSSRSMicrosoft Server OS

Avatar of undefined
Last Comment
spen_lang
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of spen_lang
spen_lang

ASKER

Thanks. Although this works perfectly in Visual Studio when I add it to my code in Reporting Services I get the followng:

User generated imageAny idea how I can fix this?
Avatar of it_saige
it_saige
Flag of United States of America image

Add Imports System.Linq

-saige-
Avatar of spen_lang
spen_lang

ASKER

Hi, I tried this but unfortunately it did not work. I have now created a Class with the function you provided in it and added as a reference to the report.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo