Laura,

I agree with "The_Fruitman" on this... Your design appears to be so
deeply flawed (it violates the very tenets of programming) that it
seems that your actual problem at hand is insignificant in comparison.
I seriously hope we have misunderstood you and you are not using a
separate form for each class... sounds like there are atleast 51 of
these classes.

On Jan 15, 8:10 pm, The_Fruitman <[email protected]> wrote:
> Please tell me you aren't building a separate form for each class.
> This is a bad design and should be avoided at all costs because of
> several issues (these are the ones that quickly come to mind):
> 1. What happens when a new class is added?  Will you have to build
> another form?
> 2. What happens if a class has been removed?  Do you need to remove or
> hide the form?
> 3. Having each class as a separate form means that you have duplicate
> code all over the place, this is also something that should be
> avoided.  For one reason, if you have to make modifications to the
> code, you have to change it in multiple areas.
>
> If you must display the listing of students for a selected class in
> another form there are other ways to do it.  For example you may pass
> the selected class id to the attendance form.  This would allow you to
> use the same form for all your classes (a much better design).  On the
> form load of the attendance form you would grab the passed in class id
> and use it as a parameter in your sql statement to populate your
> dataset.  From there you can then do your adding of information from
> the dataset to the listbox or whatever other controls you wish to
> populate witih the information.
>
> On Jan 14, 9:01 am, Laura <[email protected]> wrote:
>
>
>
> > 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- Hide quoted text -
>
> - Show quoted text -

Reply via email to