学生信息管理系统代码.docx
《学生信息管理系统代码.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统代码.docx(19页珍藏版)》请在冰豆网上搜索。
![学生信息管理系统代码.docx](https://file1.bdocx.com/fileroot1/2023-4/21/8e24943d-c5ae-473e-ae61-3164dff9b4c5/8e24943d-c5ae-473e-ae61-3164dff9b4c51.gif)
学生信息管理系统代码
主要代码如下:
1、登录界面代码:
DimcnAsNewADODB.Connection
DimrstAsNewADODB.Recordset
PrivateSubCommand1_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
Statici%
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
usna=Trim(Text1.Text)
mysql="select*from用户表where用户名='"&usna&"'"
rst.Openmysql,cn
Ifrst.EOFThen
MsgBox"用户名不存在!
"
cn.Close
Text1.Text=""
Text2.Text=""
Text1.SetFocus
Else
IfTrim(rst("密码"))=Trim(Text2.Text)Then
管理界面.Show
Else
i=i+1
Ifi<3Then
MsgBox"用户名或密码错误!
",vbOKOnly+vbExclamation,"警告"
cn.Close
Text2.Text=""
Text1.Text=""
Text1.SetFocus
Else
MsgBox"该用户已被锁定!
",vbOKOnly+vbExclamation,"警告"
EndIf
EndIf
EndIf
EndSub
PrivateSubCommand2_Click()
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub
2、管理界面代码:
PrivateSubSinsert_Click()
添加学生信息.Show
EndSub
PrivateSubSselect_Click()
查询学生信息.Show
EndSub
PrivateSubsustu_Click()
查询更新学生信息.Show
EndSub
PrivateSubxgmm_Click()
修改密码.Show
EndSub
PrivateSubyhzc_Click()
用户注册.Show
EndSub
3、查询学生信息代码:
DimcnAsNewADODB.Connection
DimrstAsNewADODB.Recordset
PrivateSubCommand1_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
IfCombo1.Text<>""Then
mysql="select*from学生信息表where系别='"&Trim(Combo1.Text)&"'"
rst.Openmysql,cn
Ifrst.EOFThen
MsgBox"没有学生!
",vbOKOnly+vbExclamation,"警告"
Combo1.Text=""
Else
WithMSFlexGrid1
.TextMatrix(0,1)="学号"
.TextMatrix(0,2)="姓名"
.TextMatrix(0,3)="性别"
.TextMatrix(0,4)="年龄"
.TextMatrix(0,5)="系别"
.TextMatrix(0,6)="班级"
MSFlexGrid1.Rows=1'每次查询自动定位到第一行
DoWhileNotrst.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
EndWith
EndIf
ElseIfCombo2.Text<>""Then
mysql="select*from学生信息表where班级='"&Trim(Combo2.Text)&"'"
rst.Openmysql,cn
Ifrst.EOFThen
MsgBox"没有学生!
",vbOKOnly+vbExclamation,"警告"
Combo1.Text=""
Else
WithMSFlexGrid1
.TextMatrix(0,1)="学号"
.TextMatrix(0,2)="姓名"
.TextMatrix(0,3)="性别"
.TextMatrix(0,4)="年龄"
.TextMatrix(0,5)="系别"
.TextMatrix(0,6)="班级"
MSFlexGrid1.Rows=1'每次查询自动定位到第一行
DoWhileNotrst.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
EndWith
EndIf
ElseIfText1.Text<>""Then
mysql="select*from学生信息表where学号='"&Trim(Text1.Text)&"'"
rst.Openmysql,cn
Ifrst.EOFThen
MsgBox"没有学生!
",vbOKOnly+vbExclamation,"警告"
Combo1.Text=""
Else
WithMSFlexGrid1
.TextMatrix(0,1)="学号"
.TextMatrix(0,2)="姓名"
.TextMatrix(0,3)="性别"
.TextMatrix(0,4)="年龄"
.TextMatrix(0,5)="系别"
.TextMatrix(0,6)="班级"
MSFlexGrid1.Rows=1'每次查询自动定位到第一行
DoWhileNotrst.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
EndWith
EndIf
Else
MsgBox"请输入查询条件!
",vbOKOnly+vbExclamation,"警告"
EndIf
EndSub
PrivateSubCommand2_Click()
Combo1.Text=""
Combo2.Text=""
Text1.Text=""
EndSub
PrivateSubCommand3_Click()
修改学生信息.Show
EndSub'修改学生信息
PrivateSubCommand4_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
mysql="deletefrom学生信息表where学号='"&Text1.Text&"'"
rst.Openmysql,cn
MsgBox"删除成功!
",vbOKOnly+vbExclamation,"警告"
EndSub
PrivateSubForm_Load()
Combo1.AddItem"信息服务学院"
Combo1.AddItem"电子信息工程系"
Combo2.AddItem"40821P"
Combo2.AddItem"40811P"
Combo2.AddItem"40822P"
Combo2.AddItem"40721P"
EndSub
4、添加学生信息代码
DimcnAsNewADODB.Connection
DimrstAsNewADODB.Recordset
PrivateSubForm_Load()
Combo1.AddItem"信息服务学院"
Combo1.AddItem"电子信息工程系"
Combo2.AddItem"40821P"
Combo2.AddItem"40811P"
Combo2.AddItem"40822P"
Combo2.AddItem"40721P"
EndSub
PrivateSubCommand1_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
DimsexAsString
usna=Trim(Text1.Text)
mysql="select*from学生信息表where学号='"&usna&"'"
rst.Openmysql,cn
Ifrst.EOFThen
rst.Close
Else
rst.Close
MsgBox"该学生信息已存在!
",vbOKOnly+vbExclamation,"警告"
Text1.Text=""
Text2.Text=""
Text3.Text=""
Combo1.Text=""
Combo2.Text=""
Option1.Value=False
Text1.SetFocus
EndIf
IfText1.Text=""Then
MsgBox"请输入学号!
",vbOKOnly+vbExclamation,"警告"
Text1.SetFocus
ExitSub
EndIf
IfText2.Text=""Then
MsgBox"请输入姓名!
",vbOKOnly+vbExclamation,"警告"
Text2.SetFocus
ExitSub
EndIf
IfText3.Text=""Then
MsgBox"请输入年龄!
",vbOKOnly+vbExclamation,"警告"
Text3.SetFocus
ExitSub
EndIf
IfOption1.ValueThen
sex="男"
Else
sex="女"
EndIf
xh=Trim(Text1.Text)
xm=Trim(Text2.Text)
xb=sex
nl=Trim(Text3.Text)
xofy=Trim(Combo1.Text)
bj=Trim(Combo2.Text)
mysql="insertinto学生信息表(学号,姓名,性别,年龄,系别,班级)values('"&xh&"','"&xm&"','"&xb&"','"&nl&"','"&xofy&"','"&bj&"')"
rst.Openmysql,cn
MsgBox("信息添加成功!
")
Text1.Text=""
Text2.Text=""
Text3.Text=""
Combo1.Text=""
Combo2.Text=""
Option1.Value=False
EndSub
5、修改密码:
DimrstAsNewADODB.Recordset
DimcnAsNewADODB.Connection
PrivateSubCommand1_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
IfText1.Text=""Then
MsgBox"请输入密码!
",vbOKOnly+vbExclamation,"警告"
Text1.SetFocus
ExitSub
EndIf
IfText2.Text=""Then
MsgBox"请输入新密码!
",vbOKOnly+vbExclamation,"警告"
Text2.SetFocus
ExitSub
EndIf
IfText3.Text=""Then
MsgBox"请确认输入的新密码!
",vbOKOnly+vbExclamation,"警告"
Text3.SetFocus
ExitSub
EndIf
IfText2.Text=Text3.TextThen
xmm=Trim(Text2.Text)
mysql="update用户表set密码='"&xmm&"'where用户名='"&登陆.Text1.Text&"'"
rst.Openmysql,cn
MsgBox("密修改成功!
")
EndIf
EndSub
PrivateSubCommand2_Click()
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub
6、修改学生信息代码:
DimcnAsNewADODB.Connection
DimrstAsNewADODB.Recordset
PrivateSubCommand1_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
usna=Trim(Text1.Text)
mysql="select*from学生信息表where学号='"&usna&"'"
rst.Openmysql,cn
rst.Close
mysql="deletefrom学生信息表where学号='"&Text1.Text&"'"
rst.Openmysql,cn
IfText1.Text=""Then
MsgBox"请输入学号!
",vbOKOnly+vbExclamation,"警告"
Text1.SetFocus
ExitSub
EndIf
IfText2.Text=""Then
MsgBox"请输入姓名!
",vbOKOnly+vbExclamation,"警告"
Text2.SetFocus
ExitSub
EndIf
IfText3.Text=""Then
MsgBox"请输入年龄!
",vbOKOnly+vbExclamation,"警告"
Text3.SetFocus
ExitSub
EndIf
IfOption1.ValueThen
sex="男"
Else
sex="女"
EndIf
xh=Trim(Text1.Text)
xm=Trim(Text2.Text)
xb=sex
nl=Trim(Text3.Text)
xofy=Trim(Combo1.Text)
bj=Trim(Combo2.Text)
mysql="insertinto学生信息表(学号,姓名,性别,年龄,系别,班级)values('"&xh&"','"&xm&"','"&xb&"','"&nl&"','"&xofy&"','"&bj&"')"
rst.Openmysql,cn
MsgBox("信息修改成功!
")
Text1.Text=""
Text2.Text=""
Text3.Text=""
Combo1.Text=""
Combo2.Text=""
Option1.Value=False
EndSub
PrivateSubForm_Load()
Combo1.AddItem"信息服务学院"
Combo1.AddItem"电子信息工程系"
Combo2.AddItem"40821P"
Combo2.AddItem"40811P"
Combo2.AddItem"40822P"
Combo2.AddItem"40721P"
EndSub
7、用户注册代码:
DimrstAsNewADODB.Recordset
DimcnAsNewADODB.Connection
PrivateSubCommand1_Click()
Setcn=NewADODB.Connection
Setrst=NewADODB.Recordset
cn.ConnectionString="Provider=SQLOLEDB.1;PersistSecurityInfo=False;UserID=sa;InitialCatalog=studentsinfo;DataSource=C1847"
cn.Open
IfText1.Text=""Then
MsgBox"请输入用户名!
",vbOKOnly+vbExclamation,"警告"
Text1.SetFocus
ExitSub
EndIf
IfText2.Text=""Then
MsgBox"请输入密码!
",vbOKOnly+vbExclamation,"警告"
Text2.SetFocus
ExitSub
EndIf
IfText3.Text=""Then
MsgBox"请再次输入密码!
",vbOKOnly+vbExclamation,"警告"
Text3.SetFocus
ExitSub
EndIf
sryhm=Trim(Text1.Text)
srmm=Trim(Text2.Text)
mysql="insertinto用户表(用户名,密码)values('"&sryhm&"','"&srmm&"')"
rst.Openmysql,cn
MsgBox("用户添加成功!
")
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub'添加用户
PrivateSubCommand2_Click()
Text1.Text=""
Text2.Text=""
Text3.Text=""
EndSub'重置按钮
PrivateSubCo