Share via

why am i getting System.Collections.Generic.List`1[System.String] when i try to print values froma list?

mush 181 Reputation points
2022-03-13T05:00:47.427+00:00

I'm trying to create a session where i store the values of certain column. so I created this list to display the value if selected but I'm getting this in the other page System.Collections.Generic.List`1[System.String] instead oof the actual values.

this is the first page's code:

Private Sub BindGrid()
    Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
    con.Open()
    Dim cmd As New SqlCommand("select distinct Name,assignment_id, Description ,cod from assignments 
        INNER Join crmsLecturerXCrsSection ON crmsLecturerXCrsSection.emp_key = assignments.emp_key
        INNER Join CRMSStudentsXCrsSection ON CRMSStudentsXCrsSection.CrsSec_id = crmsLecturerXCrsSection.CrsSec_id
        INNER JOIN CRMS_CourseXSection ON CRMS_CourseXSection.CrsSec_id = CRMSStudentsXCrsSection.CrsSec_id
        INNER JOIN CRMSECTIONS ON CRMSECTIONS.SEC_ID = CRMS_CourseXSection.SEC_ID
        left JOIN crmscourses ON crmscourses.crs_id = CRMS_CourseXSection.crs_id
        INNER JOIN CRMS_CourseXSection cs ON CRMS_CourseXSection.SEC_ID = CRMSECTIONS.SEC_ID
        INNER JOIN CRMSSEMESTER ON CRMSSEMESTER.SEM_ID = CRMS_CourseXSection.SEM_ID
        where  CRMSSEMESTER.SEM_ID='1'   
        and crmsLecturerXCrsSection.emp_key='436' and crmscourses.crs_desc='" + Session("crs") + "'", con)




    Dim da As New SqlDataAdapter(cmd)
    Dim dt As New DataTable()
    da.Fill(dt)

    Dim listIDs As New List(Of String)
    Dim row As DataRow
    For Each row In dt.Rows
        listIDs.Add(row("assignment_id"))
    Next
    Session("assid") = listIDs




    cmd.Connection = con

    GridView1.DataSource = cmd.ExecuteReader()
    GridView1.DataBind()




End Sub

this is the second's:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = Session("assid").ToString()

    Dim con1 As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)

    Dim cmd1 As New SqlCommand("select * from assignments where assignment_id ='" + String.Join(",", Session("assid")) + "'", con1)
End Sub
Developer technologies | ASP.NET | Other
0 comments No comments

Answer accepted by question author
  1. Sreeju Nair 12,761 Reputation points
    2022-03-13T07:32:24.783+00:00

    Session("assid") is of type List of String, and for list, when you call tostring method, it will simply print the type. try the following lines of code in your page_load method.

    Dim assignments = TryCast(CObj(Session("assid")), List(Of String))
    Label1.Text = String.Join(",", assignments)
    

    You may notice, since assid contains a list of string, we can use string method to join them.

    Hope this helps

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.