📄 form5.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form 添加成绩记录
Caption = "添加成绩记录"
ClientHeight = 5175
ClientLeft = 60
ClientTop = 345
ClientWidth = 7875
LinkTopic = "Form1"
ScaleHeight = 5175
ScaleWidth = 7875
StartUpPosition = 3 'Windows Default
Begin VB.Frame Frame1
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 4815
Left = 240
TabIndex = 0
Top = 120
Width = 7455
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 6000
Top = 4080
Visible = 0 'False
Width = 1215
_ExtentX = 2143
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=成绩查询"
OLEDBString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=成绩查询"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = "sa"
RecordSource = "select * from cjpm"
Caption = ""
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.CommandButton Command1
Caption = "确 定"
Height = 495
Left = 4440
TabIndex = 18
Top = 3120
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "退 出"
Height = 495
Left = 5760
TabIndex = 17
Top = 3120
Width = 1095
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 16
Top = 480
Width = 2175
End
Begin VB.TextBox Text2
Height = 375
Left = 1200
TabIndex = 15
Top = 1320
Width = 2175
End
Begin VB.TextBox Text4
Height = 375
Left = 1200
TabIndex = 14
Top = 3120
Width = 2175
End
Begin VB.TextBox Text6
Height = 375
Left = 4800
TabIndex = 13
Top = 480
Width = 2295
End
Begin VB.TextBox Text8
Height = 375
Left = 4800
TabIndex = 12
Top = 1200
Width = 2295
End
Begin VB.TextBox Text9
Height = 375
Left = 4800
TabIndex = 11
Top = 2040
Width = 2295
End
Begin VB.ComboBox Combo1
Height = 315
Left = 1200
TabIndex = 2
Text = "请选择性别"
Top = 2280
Width = 2175
End
Begin VB.ComboBox Combo2
Height = 315
Left = 1200
TabIndex = 1
Text = "请选择班级"
Top = 3960
Width = 2175
End
Begin VB.Label Label1
Caption = "学 号:"
Height = 255
Left = 360
TabIndex = 10
Top = 600
Width = 855
End
Begin VB.Label Label2
Caption = "姓 名:"
Height = 495
Left = 360
TabIndex = 9
Top = 1440
Width = 855
End
Begin VB.Label Label3
Caption = "性 别:"
Height = 375
Left = 360
TabIndex = 8
Top = 2280
Width = 855
End
Begin VB.Label Label4
Caption = "年 龄:"
Height = 255
Left = 360
TabIndex = 7
Top = 3120
Width = 855
End
Begin VB.Label Label5
Caption = "班 级:"
Height = 375
Left = 360
TabIndex = 6
Top = 3960
Width = 855
End
Begin VB.Label Label6
Caption = "课程号:"
Height = 255
Left = 3840
TabIndex = 5
Top = 600
Width = 855
End
Begin VB.Label Label8
Caption = "成 绩:"
Height = 375
Left = 3960
TabIndex = 4
Top = 1320
Width = 855
End
Begin VB.Label Label9
Caption = "学 分:"
Height = 255
Left = 3960
TabIndex = 3
Top = 2160
Width = 855
End
End
End
Attribute VB_Name = "添加成绩记录"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
'以下代码用于出错处理
Dim MsgText As String
Dim sMeg As String
If Text1.Text = "" Then
sMeg = "学号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Exit Sub
ElseIf Not IsNumeric(Text1.Text) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Text1.Text = ""
Exit Sub
Else
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim sOut As String
Dim Count As Integer
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Set properties of the Connection.
cn.ConnectionString = "DSN=成绩查询;UID=sa;PWD=sa;"
cn.ConnectionTimeout = 30
cn.Open
sSQL = "SELECT * FROM xsxx where 学号=" & Text1.Text & ""
Set rs = cn.Execute(sSQL)
If Not rs.BOF And Not rs.EOF Then
MsgBox "该学号已存在!请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.Text = ""
Exit Sub
End If
End If
If Text2.Text = "" Then
MsgBox "姓名不能为空,请重填!", vbOKOnly, "输入错误"
Exit Sub
End If
If Text4.Text = "" Then
sMeg = "年龄不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Exit Sub
Else
If Not IsNumeric(Text4.Text) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Text4.Text = ""
Exit Sub
End If
End If
If Text6.Text = "" Then
sMeg = "课程号不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text6.SetFocus
Exit Sub
Else
If Not IsNumeric(Text6.Text) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text6.SetFocus
Text6.Text = ""
Exit Sub
End If
End If
If Text8.Text = "" Then
sMeg = "成绩不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text8.SetFocus
Exit Sub
Else
If Not IsNumeric(Text8.Text) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text8.SetFocus
Text8.Text = ""
Exit Sub
End If
End If
If Text9.Text = "" Then
sMeg = "学分不能为空"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Text9.SetFocus
Exit Sub
Else
If Not IsNumeric(Text9.Text) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Text9.SetFocus
Text9.Text = ""
Exit Sub
End If
End If
If Combo1.Text = "请选择性别" Then
MsgBox "性别不能为空,请重填!", vbOKOnly, "输入错误"
Exit Sub
End If
If Combo2.Text = "请选择班级" Then
MsgBox "班级不能为空,请重填!", vbOKOnly, "输入错误"
Exit Sub
End If
cn.Execute "insert into xsxx (学号,姓名,性别,年龄,班级) values(" & Text1.Text & ",'" & Text2.Text & " ','" & Combo1.Text & "' , " & Text4.Text & "," & Combo2.Text & ") "
cn.Execute "insert into xxxx (学号,课程号,成绩) values(" & Text1.Text & ",'" & Text6.Text & "'," & Text8.Text & ") "
MsgBox "学生成绩增加成功", vbOKOnly, "学生成绩增加成功"
Text1.Text = ""
Text2.Text = ""
Text4.Text = ""
Text6.Text = ""
Text8.Text = ""
Text9.Text = ""
Combo1.Text = "请选择性别"
Combo2.Text = "请选择班级"
cn.Close
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim sOut As String
Dim Count As Integer
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Set properties of the Connection.
cn.ConnectionString = "DSN=成绩查询;UID=sa;PWD=sa;"
cn.ConnectionTimeout = 30
cn.Open
'以下代码用于初始化COMBO1和COMBO2控件和DTPICKER1控件
Combo1.AddItem "男"
Combo1.AddItem "女"
Combo2.AddItem "1"
Combo2.AddItem "2"
Combo2.AddItem "3"
Combo2.AddItem "4"
cn.Close
End Sub
Private Sub Label7_Click()
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -