Hi,

I have a database with a Student table and a Class table. A number of
students are members of a particular class.

On my windows form I need to display student names in a listbox. I
then have a different form for each class. So for example (as per code
below) this form is for Class51. The code I have so far is reading in
all student names into the listbox. I need it to read in the names of
those students in Class51.

Each class has a classID. I know in SQL I would simply say SELECT *
FROM STUDENT WHERE CLASSID = 8, but what do I need to add to my code
here.

Any help would be really appreciated.

Private Sub frmAttendace51_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

        'clear data set of any existing data
        objDataSet.Clear()
        'fill schema
        objStudentDA.FillSchema(objDataSet, SchemaType.Source,
"tblStudent")
        'fill data set with info from data adapter
        objStudentDA.Fill(objDataSet, "tblStudent")

        'fill the data set with info from tblClass
        objClassDA.FillSchema(objDataSet, SchemaType.Source,
"tblClass")
        objClassDA.Fill(objDataSet, "tblClass")

        'fill the data set with info from tblClass
        objAttendanceDA.FillSchema(objDataSet, SchemaType.Source,
"tblAttendance")
        objAttendanceDA.Fill(objDataSet, "tblAttendance")

        'setup the relationship
        objDataSet.Relations.Clear()
        objDataSet.Relations.Add("Class2Student", _
                                 objDataSet.Tables("tblClass").Columns
("ClassID"), _
                                 objDataSet.Tables
("tblStudent").Columns("ClassID"))
        objDataSet.Relations.Add("Student2Attendance", _
                                 objDataSet.Tables
("tblStudent").Columns("StudentID"), _
                                 objDataSet.Tables
("tblAttendance").Columns("StudentID"))

        lstStudents51.Items.Clear()



        Dim i As Integer
        Dim strSurname As String
        Dim strFirstName As String
        For i = 1 To objDataSet.Tables("tblStudent").Rows.Count
            strSurname = objDataSet.Tables("tblStudent").Rows(i -
1).Item("SName")
            strFirstName = objDataSet.Tables("tblStudent").Rows(i -
1).Item("FName")
            lstStudents51.Items.Add(strSurname + ", " + strFirstName)
        Next

        lstStudents51.SelectedIndex = 0

Reply via email to