学生成绩管理相关代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

附录

3.1 连接数据库的模块代码

Public cnn As New ADODB.Connection '新建一个数据源

Public qy1 As New ADODB.Recordset '数据一个记录集

Public qy2 As New ADODB.Recordset '数据一个记录集

Sub Main()

tkOpenAccessDB App.Path & "\base.mdb" '连接数据库

If qy1.State = adStateOpen Then '表状态

qy1.Close

End If

qy1.Open "select * from 登陆", cnn, adOpenStatic, adLockReadOnly, adCmdText '查询表内是否有数据

If qy1.RecordCount = 0 Then

Set qy1 = cnn.Execute("insert into 登陆 values('admin','admin','超级管理员')") '表内无数据执行此语句新建用户

End If

Form3.Show

End Sub

Private Sub tkOpenAccessDB( _

tkFileName As String, _

Optional tkUserID As String, _

Optional tkPassword As String _

) '连接数据库参数

On Error GoTo tkFinish

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=" & tkFileName & ";" & _

"Mode=Share Deny None;" & _

"Extended Properties=;" & _

"Jet OLEDB:System database=;" & _

"Jet OLEDB:Registry Path=;" & _

"Jet OLEDB:Database Password=;" & _

"Jet OLEDB:Engine Type=5;" & _

"Jet OLEDB:Database Locking Mode=1;" & _

"Jet OLEDB:Global Partial Bulk Ops=2;" & _

"Jet OLEDB:Global Bulk Transactions=1;" & _

"Jet OLEDB:New Database Password=;" & _

"Jet OLEDB:Create System Database=False;" & _

"Jet OLEDB:Encrypt Database=False;" & _

"Jet OLEDB:Don't Copy Locale on Compact=False;" & _ "Jet OLEDB:Compact Without Replica Repair=False;" & _ "Jet OLEDB:SFP=False;" & _

tkUserID, _

tkPassword

Exit Sub

tkFinish:

MsgBox Err.Description

End

End Sub

3.2 登陆界面与代码

Private Sub XPButton1_Click()

On Error GoTo finish

user = Text1.Text

Set mdbrs = mdbconn.Execute("select * from 登陆 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'")

If mdbrs.EOF = True Then

Text1.Text = ""

Text2.Text = ""

Text1.SetFocus

MsgBox "用户名和密码不正确!!"

Else

user111 = mdbrs.Fields(0)

sup = mdbrs.Fields(2)

If mdbrs.Fields(2) = "超级管理员" Then

admin = True

'MsgBox "您是超级管理员!!"

' MsgBox user

Else

admin = False

'MsgBox "您不是超级管理员!!"

End If

Unload Me

MDIForm1.Show

End If

Exit Sub

finish:

MsgBox Err.Description

End Sub

Private Sub XPButton2_Click()

End

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then

Call XPButton1_Click

End If

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then

Call XPButton1_Click

End If

End Sub

相关文档
最新文档