Results 1 to 5 of 5

Thread: Casting Error?? [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    4

    Resolved Casting Error?? [RESOLVED]

    What i am trying to do is load a combo box on a form frmStudents. The way i am going about doing it is my frmstudent on load event has this code

    VB Code:
    1. Private stu As Student
    2.     Private Sub frmDisplayStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         stu = New Student
    4.         cboStudents.DataSource = stu.GetStudents
    5.         cboStudents.DisplayMember = "FIRSTNAME"
    6.     End Sub

    stu calls to class Student which as a function of GetStudents which does this

    VB Code:
    1. Public Function GetStudents() As ArrayList
    2.  
    3.         conn = New SqlConnection(connstring)
    4.         Dim sql As String = "SELECT * FROM Student"
    5.         comm = New SqlCommand(sql, conn)
    6.         Dim stu As New Student
    7.         Dim students As New ArrayList
    8.  
    9.         conn.Open()
    10.         Dim reader As SqlDataReader = comm.ExecuteReader(CommandBehavior.CloseConnection)
    11.  
    12.         Do While reader.Read
    13.             stu = New Student(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), _
    14.                                 reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetString(7))
    15.             students.Add(stu)
    16.         Loop
    17.         reader.Close()
    18.         conn.Close()
    19.  
    20.         Return students
    21.     End Function

    When i try to load the form it says i have a casting error? specifically "Specified cast is not valid."
    Last edited by SaitStudent; Nov 12th, 2006 at 11:43 PM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width