I have a property active to indicate status of an employee. Along with all the details, i extract the details from an employee table into a dataset, but however i am not able to get the value present in active as i get an invalid cast exception.

This is the property declaration.


rivate Active As SqlTypes.SqlBoolean
        Public Property Actv() As SqlTypes.SqlBoolean
                Return Active
            End Get
            Set(ByVal value As SqlTypes.SqlBoolean)
                Active = value
            End Set
        End Property

This is the data access code , i get an error when in the while loop , i add the details into the employee object. Please fill me in on any mistakes that i have made.

Public Function GetEmployeeDetails(ByVal lname As String) As List(Of Employee)
            Dim con As New SqlConnection
            con.ConnectionString = constring
            Dim sql As String = "select * from Employee where LoginName = '" + lname + "'"
            Dim com As New SqlCommand(sql, con)   ' Declaring a command object

            Dim dr As SqlDataReader = com.ExecuteReader()
            Dim lstEmp As New List(Of Employee)

            If dr.HasRows Then

                While dr.Read()
                    Dim emp As New Employee With {.EmpID = dr.GetInt32(0), .EmpName = dr.GetString(1), .Bdate = dr.GetDateTime(2),
                                                  .DOJ = dr.GetDateTime(3), .LogName = lname, .pswd = dr.GetString(5), .DeptID = dr.GetInt32(6),
                                                  .Addr = dr.GetString(7), .Bsc = dr.GetInt32(8), .Tallow = dr.GetInt32(9),
                                                  .Hrallow = dr.GetInt32(10), .Actv = dr.GetInt32(11)}
                End While
                Return lstEmp
                Return lstEmp
            End If
        Catch ex As SqlException
            Throw ex

        End Try

    End Function
This question has already been answered. Start a new discussion instead.