The Student Information System has been debugged. The last point is to improve the two modules of the class and the student.
In actual life, if a class 10 does not exist, the students in this class will not exist. first, we plan to create a foreign key for the primary key. However, since we didn't think of this aspect when creating a table at the beginning, it may be difficult to use this method, so I gave up. to solve this problem, I chose to write code to solve this problem. take the relationship between the class and the students. If the class does not exist, the students in the class will not exist. that is to say, when I delete the student's class, the student in this class will also be deleted accordingly. even though /? But how can we implement it in the form of code? Below I will show my code as follows.
Private sub deletecommand_click ()
Dim txtsql as string
Dim msgtext as string
Dim mrcstu as new ADODB. recordset
Mybookmark = MRC. bookmark
Str2 $ = msgbox ("delete current record", vbokcancel, "delete current record ")
'When there is information in the record set, delete it as follows:
If str2 $ = vbok then
MRC. movenext
If MRC. EOF then
MRC. movefirst
'When there is one record left in the record set
Mybookmark = MRC. bookmark
MRC. movelast
MRC. Delete
MRC. Bookmark = mybookmark
Txtsql = "select * From student_info where (class_no = '" & txtclassno & "') and (grade = '" & combograde. Text &"')"
Set mrcstu = executesql (txtsql, msgtext)
If mrcstu. EOF then
Else
Mrcstu. movefirst
While (not mrcstu. EOF)
Mrcstu. Delete
Mrcstu. movenext
Wend
End if
Txtsql = "select * From class_info"
Set MRC = executesql (txtsql, msgtext)
If MRC. EOF then
'When there is no record in the record set
Txtclassno. Text = ""
Combograde. Text = ""
Txtdirector. Text = ""
Txtclassroom. Text = ""
Msgbox "no records have been recorded currently", vbokonly, "tip"
Unload me
End if
Else
Mybookmark = MRC. bookmark' when more than one record is left in the record set
MRC. moveprevious
MRC. Delete
MRC. Bookmark = mybookmark
Txtsql = "select * From class_info"
Set MRC = executesql (txtsql, msgtext)
Txtsql = "select * From student_info where (class_no = '" & txtclassno & "') and (grade = '" & combograde. Text &"')"
Set mrcstu = executesql (txtsql, msgtext)
If mrcstu. EOF then
Else
Mrcstu. movefirst
While (not mrcstu. EOF)
Mrcstu. Delete
Mrcstu. movenext
Wend
End if
End if
Call viewdata
Else
MRC. Bookmark = mybookmark
Call viewdata
End if
End sub
Although this method is a bit stupid and has a lot of code, it seems to be troublesome, it is also a solution after all. I still hope that I can show it. Other students can share it in a better way.
In fact, sometimes it is easy to solve some problems as long as you know the ideal in your life.