Connection and deletion in the Student Information System

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.