资源描述
主要代码如下:
1、登录界面代码:
Dim cn As New ADODB。Connection
Dim rst As New ADODB。Recordset
Private Sub Command1_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB。Recordset
Static i%
cn。ConnectionString = "Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn.Open
usna = Trim(Text1。Text)
mysql = ”select * from 用户表 where 用户名=’" & usna & ”’”
rst。Open mysql, cn
If rst。EOF Then
MsgBox ”用户名不存在!”
cn。Close
Text1.Text = "”
Text2.Text = ””
Text1。SetFocus
Else
If Trim(rst("密码”)) = Trim(Text2.Text) Then
管理界面.Show
Else
i = i + 1
If i < 3 Then
MsgBox ”用户名或密码错误!”, vbOKOnly + vbExclamation, "警告”
cn。Close
Text2。Text = ””
Text1。Text = "”
Text1。SetFocus
Else
MsgBox ”该用户已被锁定!", vbOKOnly + vbExclamation, "警告"
End If
End If
End If
End Sub
Private Sub Command2_Click()
Text1。Text = ””
Text2。Text = "”
Text3。Text = "”
End Sub
2、管理界面代码:
Private Sub Sinsert_Click()
添加学生信息。Show
End Sub
Private Sub Sselect_Click()
查询学生信息.Show
End Sub
Private Sub sustu_Click()
查询更新学生信息.Show
End Sub
Private Sub xgmm_Click()
修改密码。Show
End Sub
Private Sub yhzc_Click()
用户注册.Show
End Sub
3、查询学生信息代码:
Dim cn As New ADODB。Connection
Dim rst As New ADODB。Recordset
Private Sub Command1_Click()
Set cn = New ADODB.Connection
Set rst = New ADODB。Recordset
cn。ConnectionString = ”Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"
cn。Open
If Combo1。Text <〉 "” Then
mysql = ”select * from 学生信息表 where 系别=’” & Trim(Combo1。Text) & ”'”
rst.Open mysql, cn
If rst.EOF Then
MsgBox ”没有学生!", vbOKOnly + vbExclamation, ”警告"
Combo1。Text = "”
Else
With MSFlexGrid1
。TextMatrix(0, 1) = ”学号"
.TextMatrix(0, 2) = ”姓名”
.TextMatrix(0, 3) = "性别"
.TextMatrix(0, 4) = "年龄"
.TextMatrix(0, 5) = ”系别”
。TextMatrix(0, 6) = "班级”
MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行
Do While Not rst.EOF
。Rows = .Rows + 1
。CellAlignment = 8
。TextMatrix(。Rows — 1, 1) = rst。Fields(”学号")
.TextMatrix(。Rows — 1, 2) = rst.Fields(”姓名")
。TextMatrix(.Rows — 1, 3) = rst。Fields("性别”)
。TextMatrix(。Rows — 1, 4) = rst。Fields("年龄")
。TextMatrix(。Rows - 1, 5) = rst。Fields(”系别”)
。TextMatrix(.Rows — 1, 6) = rst.Fields("班级")
rst。MoveNext
Loop
End With
End If
ElseIf Combo2.Text <〉 "" Then
mysql = ”select * from 学生信息表 where 班级=’” & Trim(Combo2.Text) & "’”
rst。Open mysql, cn
If rst.EOF Then
MsgBox ”没有学生!”, vbOKOnly + vbExclamation, "警告”
Combo1。Text = ""
Else
With MSFlexGrid1
。TextMatrix(0, 1) = ”学号”
。TextMatrix(0, 2) = "姓名"
。TextMatrix(0, 3) = ”性别”
。TextMatrix(0, 4) = ”年龄”
.TextMatrix(0, 5) = ”系别”
。TextMatrix(0, 6) = ”班级”
MSFlexGrid1。Rows = 1 '每次查询自动定位到第一行
Do While Not rst。EOF
.Rows = .Rows + 1
。CellAlignment = 8
.TextMatrix(.Rows - 1, 1) = rst.Fields(”学号”)
。TextMatrix(。Rows — 1, 2) = rst。Fields(”姓名")
.TextMatrix(.Rows — 1, 3) = rst.Fields(”性别”)
.TextMatrix(。Rows - 1, 4) = rst。Fields("年龄")
.TextMatrix(。Rows — 1, 5) = rst.Fields(”系别")
.TextMatrix(.Rows — 1, 6) = rst。Fields(”班级")
rst。MoveNext
Loop
End With
End If
ElseIf Text1。Text 〈> "” Then
mysql = "select * from 学生信息表 where 学号=’" & Trim(Text1.Text) & ”’”
rst。Open mysql, cn
If rst.EOF Then
MsgBox ”没有学生!", vbOKOnly + vbExclamation, ”警告"
Combo1.Text = "”
Else
With MSFlexGrid1
。TextMatrix(0, 1) = ”学号”
。TextMatrix(0, 2) = "姓名”
。TextMatrix(0, 3) = "性别”
。TextMatrix(0, 4) = ”年龄”
。TextMatrix(0, 5) = ”系别”
。TextMatrix(0, 6) = "班级”
MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行
Do While Not rst.EOF
.Rows = 。Rows + 1
。CellAlignment = 8
。TextMatrix(.Rows - 1, 1) = rst。Fields(”学号”)
。TextMatrix(.Rows - 1, 2) = rst.Fields(”姓名”)
.TextMatrix(.Rows — 1, 3) = rst.Fields("性别")
。TextMatrix(.Rows - 1, 4) = rst。Fields("年龄”)
。TextMatrix(。Rows — 1, 5) = rst。Fields(”系别”)
.TextMatrix(.Rows - 1, 6) = rst。Fields(”班级”)
rst.MoveNext
Loop
End With
End If
Else
MsgBox ”请输入查询条件!”, vbOKOnly + vbExclamation, ”警告”
End If
End Sub
Private Sub Command2_Click()
Combo1。Text = ””
Combo2。Text = "”
Text1。Text = ”"
End Sub
Private Sub Command3_Click()
修改学生信息.Show
End Sub ’修改学生信息
Private Sub Command4_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB。Recordset
cn。ConnectionString = "Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn。Open
mysql = "delete from 学生信息表 where 学号=’" & Text1。Text & "'”
rst。Open mysql, cn
MsgBox "删除成功!", vbOKOnly + vbExclamation, ”警告"
End Sub
Private Sub Form_Load()
Combo1.AddItem "信息服务学院”
Combo1。AddItem ”电子信息工程系”
Combo2。AddItem "40821P”
Combo2。AddItem "40811P”
Combo2。AddItem "40822P”
Combo2。AddItem ”40721P”
End Sub
4、添加学生信息代码
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Private Sub Form_Load()
Combo1.AddItem ”信息服务学院"
Combo1。AddItem ”电子信息工程系”
Combo2。AddItem "40821P"
Combo2。AddItem ”40811P”
Combo2.AddItem ”40822P”
Combo2.AddItem ”40721P”
End Sub
Private Sub Command1_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB.Recordset
cn。ConnectionString = ”Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn。Open
Dim sex As String
usna = Trim(Text1.Text)
mysql = ”select * from 学生信息表 where 学号=’” & usna & "’"
rst。Open mysql, cn
If rst。EOF Then
rst。Close
Else
rst。Close
MsgBox ”该学生信息已存在!”, vbOKOnly + vbExclamation, ”警告”
Text1。Text = ""
Text2。Text = ””
Text3.Text = ””
Combo1。Text = ””
Combo2。Text = ””
Option1.Value = False
Text1。SetFocus
End If
If Text1.Text = ”” Then
MsgBox ”请输入学号!”, vbOKOnly + vbExclamation, ”警告”
Text1。SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox ”请输入姓名!”, vbOKOnly + vbExclamation, ”警告"
Text2。SetFocus
Exit Sub
End If
If Text3.Text = ”” Then
MsgBox "请输入年龄!", vbOKOnly + vbExclamation, ”警告”
Text3。SetFocus
Exit Sub
End If
If Option1.Value Then
sex = ”男”
Else
sex = ”女”
End If
xh = Trim(Text1。Text)
xm = Trim(Text2。Text)
xb = sex
nl = Trim(Text3。Text)
xofy = Trim(Combo1。Text)
bj = Trim(Combo2。Text)
mysql = ”insert into 学生信息表(学号,姓名,性别,年龄,系别,班级) values (’" & xh & ”’,'” & xm & "’,’" & xb & ”’,'" & nl & "’,'" & xofy & ”’,'" & bj & "')”
rst.Open mysql, cn
MsgBox (”信息添加成功!")
Text1.Text = ””
Text2.Text = "”
Text3。Text = ””
Combo1。Text = ””
Combo2。Text = ””
Option1.Value = False
End Sub
5、修改密码:
Dim rst As New ADODB。Recordset
Dim cn As New ADODB.Connection
Private Sub Command1_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB.Recordset
cn。ConnectionString = "Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn.Open
If Text1。Text = ”" Then
MsgBox ”请输入密码!", vbOKOnly + vbExclamation, ”警告”
Text1。SetFocus
Exit Sub
End If
If Text2。Text = ”” Then
MsgBox "请输入新密码!", vbOKOnly + vbExclamation, ”警告”
Text2。SetFocus
Exit Sub
End If
If Text3。Text = "" Then
MsgBox ”请确认输入的新密码!”, vbOKOnly + vbExclamation, "警告"
Text3。SetFocus
Exit Sub
End If
If Text2。Text = Text3。Text Then
xmm = Trim(Text2。Text)
mysql = ”update 用户表 set 密码 = ’" & xmm & ”' where 用户名 = '" & 登陆。Text1.Text & ”’”
rst。Open mysql, cn
MsgBox (”密修改成功!")
End If
End Sub
Private Sub Command2_Click()
Text1。Text = ""
Text2。Text = ""
Text3。Text = ”"
End Sub
6、修改学生信息代码:
Dim cn As New ADODB.Connection
Dim rst As New ADODB。Recordset
Private Sub Command1_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB.Recordset
cn.ConnectionString = ”Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"
cn。Open
usna = Trim(Text1.Text)
mysql = ”select * from 学生信息表 where 学号=’” & usna & ”'”
rst.Open mysql, cn
rst.Close
mysql = ”delete from 学生信息表 where 学号=’” & Text1.Text & ”'”
rst.Open mysql, cn
If Text1。Text = ”” Then
MsgBox ”请输入学号!”, vbOKOnly + vbExclamation, "警告"
Text1。SetFocus
Exit Sub
End If
If Text2.Text = ”" Then
MsgBox "请输入姓名!”, vbOKOnly + vbExclamation, ”警告"
Text2。SetFocus
Exit Sub
End If
If Text3。Text = ”” Then
MsgBox ”请输入年龄!”, vbOKOnly + vbExclamation, ”警告”
Text3。SetFocus
Exit Sub
End If
If Option1。Value Then
sex = ”男”
Else
sex = ”女"
End If
xh = Trim(Text1。Text)
xm = Trim(Text2。Text)
xb = sex
nl = Trim(Text3.Text)
xofy = Trim(Combo1。Text)
bj = Trim(Combo2.Text)
mysql = ”insert into 学生信息表(学号,姓名,性别,年龄,系别,班级) values ('” & xh & ”’,'" & xm & ”’,'” & xb & "’,’” & nl & ”','” & xofy & "’,’" & bj & ”')”
rst.Open mysql, cn
MsgBox ("信息修改成功!")
Text1。Text = ””
Text2.Text = "”
Text3.Text = ””
Combo1.Text = ””
Combo2。Text = ””
Option1。Value = False
End Sub
Private Sub Form_Load()
Combo1。AddItem "信息服务学院"
Combo1。AddItem ”电子信息工程系"
Combo2.AddItem ”40821P"
Combo2。AddItem ”40811P"
Combo2。AddItem "40822P”
Combo2.AddItem ”40721P”
End Sub
7、用户注册代码:
Dim rst As New ADODB.Recordset
Dim cn As New ADODB。Connection
Private Sub Command1_Click()
Set cn = New ADODB.Connection
Set rst = New ADODB.Recordset
cn。ConnectionString = ”Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn。Open
If Text1。Text = ”" Then
MsgBox ”请输入用户名!”, vbOKOnly + vbExclamation, "警告"
Text1。SetFocus
Exit Sub
End If
If Text2。Text = "” Then
MsgBox ”请输入密码!", vbOKOnly + vbExclamation, ”警告"
Text2.SetFocus
Exit Sub
End If
If Text3。Text = ”” Then
MsgBox ”请再次输入密码!”, vbOKOnly + vbExclamation, ”警告”
Text3。SetFocus
Exit Sub
End If
sryhm = Trim(Text1。Text)
srmm = Trim(Text2.Text)
mysql = ”insert into 用户表(用户名,密码) values (’" & sryhm & ”’,’” & srmm & ”’)”
rst。Open mysql, cn
MsgBox (”用户添加成功!”)
Text1。Text = ””
Text2。Text = ""
Text3。Text = ”"
End Sub '添加用户
Private Sub Command2_Click()
Text1。Text = ”"
Text2。Text = ””
Text3。Text = ""
End Sub ’重置按钮
Private Sub Command3_Click()
Set cn = New ADODB.Connection
Set rst = New ADODB.Recordset
cn.ConnectionString = ”Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn。Open
usna = Trim(Text1。Text)
mysql = "select * from 用户表 where 用户名=’" & usna & ”’”
rst。Open mysql, cn
If rst。EOF Then
MsgBox ”用户名可用!”
Else
MsgBox "用户名已存在!", vbOKOnly + vbExclamation, "警告”
Text1。Text = "”
Text2.Text = "”
Text3.Text = ”"
Text1。SetFocus
Exit Sub
End If
End Sub '检查用户名
Private Sub Command4_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB。Recordset
cn.ConnectionString = ”Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn。Open
usna = Trim(Text1。Text)
mysql = ”select * from 用户表 where 用户名=’” & usna & ”’”
rst。Open mysql, cn
If rst.EOF Then
MsgBox ”无此用户名,删除不成功!”, vbOKOnly + vbExclamation, ”警告”
Else
rst。Close
usna = Trim(Text1。Text)
mysql = ”delete from 用户表 where 用户名=’" & usna & ”’"
rst.Open mysql, cn
MsgBox ”删除成功!”, vbOKOnly + vbExclamation, "警告"
Text1。Text = ””
Text2.Text = ””
Text3。Text = ””
Text1.SetFocus
End If
End Sub ’删除用户
Private Sub Command5_Click()
Set cn = New ADODB。Connection
Set rst = New ADODB。Recordset
cn。ConnectionString = ”Provider=SQLOLEDB。1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”
cn。Open
mysql = ”select * from 用户表 "
rst。Open mysql, cn
If rst.EOF Then
MsgBox ”出错!”, vbOKOnly + vbExclamation, ”警告"
End If
With MSFlexGrid1
.TextMatrix(0, 1) = ”用户名”
.TextMatrix(0, 2) = ”密码”
MSFlexGrid1.Rows = 1 ’每次查询自动定位到第一行
Do While Not rst。EOF
。Rows = 。Rows + 1
。CellAlignment = 8
。TextMatrix(.Rows - 1, 1) = rst。Fields(”用户名”)
.TextMatrix(.Rows - 1, 2) = rst。Fields("密码”)
rst。MoveNext
Loop
End With
rst。Close
End Sub ’查询用户表
展开阅读全文