日期:2014-05-16 浏览次数:20640 次
在进行机房收费系统的时候,里面有不少的操作。需要同时操作多个数据库。
比如,用户的注册操作。在用户注册的同时,分别执行两个操作。
1.把用户的信息写入到学生信息表
2.把用户的充值信息写入到数据库的充值记录表中
面对同一个操作,进行多步数据库的操作。有两种可行方案:
第一:
进行充值操作的时候,需要把充值信息写入到充值记录表,也要把学生信息的金额数进行更改。
Private Sub cmdSave_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
If testNull(txtCardNo.Text) Then
MsgBox "卡号不允许为空!", vbOKOnly + vbExclamation, "警告"
txtCardNo.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(txtCardNo.Text)) Then
MsgBox "卡号请输入数字!", vbOKOnly + vbExclamation, "警告"
txtCardNo.SetFocus
Exit Sub
End If
'检验卡号是否重复
txtSQL = "select * from student_Info where cardno='" & txtCardNo.Text & "'" & "and status='使用'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF = False Then
MsgBox "卡号已经存在,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtCardNo.SetFocus
Exit Sub
End If
If testNull(txtStudentNo.Text) Then
MsgBox "学号不允许为空!", vbOKOnly + vbExclamation, "警告"
txtStudentNo.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(txtStudentNo.Text)) Then
MsgBox "学号必须为数字!", vbOKOnly + vbExclamation, "警告"
txtStudentNo.SetFocus
Exit Sub
End If
'检验 学号 是否重复
txtSQL = "select * from student_Info where studentno='" & txtStudentNo.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then
MsgBox "此学号已被使用!", vbOKOnly + vbExclamation, "警告"
txtStudentNo.SetFocus
Exit Sub
End If
'以下 为验证 其他信息的限制
If testNull(txtName.Text) Then
MsgBox "姓名不能为空!", vbOKOnly + vbExclamation, "警告"
txtName.SetFocus
Exit Sub
End If
If testNull(txtCollege.Text) Then
MsgBox "学院不能为空!", vbOKOnly + vbExclamation, "警告"
txtCollege.SetFocus
Exit Sub
End If
If testNull(txtMajor.Text) Then
MsgBox "专业不能为空!", vbOKOnly + vbExclamation, "警告"
txtMajor.SetFocus
Exit Sub
End If
If testNull(txtGrade.Text) Then
MsgBox "年级不能为空!", vbOKOnly + vbExclamation, "警告"
txtGrade.SetFocus
Exit Sub
End If
If testNull(txtClass.Text) Then
MsgBox "班级不能为空!", vbOKOnly + vbExclamation, "警告"
txtClass.SetFocus
Exit Sub
End If
If testNull(txtCash.Text) Then
MsgBox "请输入金额!", vbOKOnly + vbExclamation, "警告"
txtCash.SetFocus
Exit Sub
End If
If Val(txtCash.Text) < 5 Then
MsgBox "注册用户最少需要5元", vbOKOnly + vbExclamation, "警告"
txtCash.SetFocus
Exit Sub
End If
'用户填写的信息检查 没有错误,现在可以进行登记信息了
txtSQL = "select * from student_Info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
mrc.Fields(0) = Trim(txtCard