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:
Private stu As Student Private Sub frmDisplayStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load stu = New Student cboStudents.DataSource = stu.GetStudents cboStudents.DisplayMember = "FIRSTNAME" End Sub
stu calls to class Student which as a function of GetStudents which does this
VB Code:
Public Function GetStudents() As ArrayList conn = New SqlConnection(connstring) Dim sql As String = "SELECT * FROM Student" comm = New SqlCommand(sql, conn) Dim stu As New Student Dim students As New ArrayList conn.Open() Dim reader As SqlDataReader = comm.ExecuteReader(CommandBehavior.CloseConnection) Do While reader.Read stu = New Student(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), _ reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetString(7)) students.Add(stu) Loop reader.Close() conn.Close() Return students End Function
When i try to load the form it says i have a casting error? specifically "Specified cast is not valid."




Reply With Quote