Hi. Can anyone help me with this code?
I have a form which takes subject name, semester and class. I put this data in a database tables using 2 ADODC’s and the connections are as follows:
ADODC3- LecturesAttended (StudentID, RollNo, Name, SubjectName)
ADODC4- Student (StudentID, RollNo, Name,Class)
I take studentid,rollno,name from student table and put it in the LecturesAttended table and assign the subject to each student.
Now the problem is that my code isn’t assigning the subject to the last student in Student table. If there are 5 students then it adds only 4students in LecturesAttended table.
Is something wrong my for loop?
Adodc3.RecordSource = "select * from LecturesAttended" Adodc4.RecordSource = "select * from Student where Class='" + cmbClass.Text + "' " Dim count As Integer For count = 0 To Adodc4.Recordset.RecordCount Adodc3.Recordset.AddNew Adodc3.Recordset.Fields("StudentID") = Adodc4.Recordset.Fields("StudentID") Adodc3.Recordset.Fields("Name") = Adodc4.Recordset.Fields("Name") Adodc3.Recordset.Fields("RollNo") = Adodc4.Recordset.Fields("Roll_No") Adodc3.Recordset.Fields("Semester") = UCase(cmbSemester.Text) Adodc3.Recordset.Fields("SubjectName") = UCase(txtSubject.Text) Adodc4.Recordset.MoveNext 'If Adodc4.Recordset.EOF = True Then 'MsgBox "Details added.", vbInformation, "Add Subject" ' Exit Sub 'End If Next count MsgBox "Details added.", vbInformation, "Add Subject" Unload Me
I tried all combinations in for loop.
Like if I change the for loop to this :
For count = 0 To Adodc4.Recordset.RecordCount – 1
Then it adds the last entry but with errors. Like EOF or BOF is true and requested operation needs a current record.