📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form2
BackColor = &H00FFC0FF&
Caption = "Form2"
ClientHeight = 4380
ClientLeft = 5175
ClientTop = 2985
ClientWidth = 5595
LinkTopic = "Form2"
ScaleHeight = 4380
ScaleWidth = 5595
Begin VB.Frame Frame1
BackColor = &H00FFC0FF&
Caption = "学生信息登记"
ForeColor = &H00000000&
Height = 3975
Left = 240
TabIndex = 0
Top = 240
Width = 5175
Begin VB.CommandButton Command4
Caption = "返回"
Height = 495
Left = 3600
TabIndex = 14
Top = 2520
Width = 1095
End
Begin VB.CommandButton Command3
Caption = "修改"
Height = 495
Left = 3600
TabIndex = 13
Top = 1560
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "返回"
Height = 495
Left = 3600
TabIndex = 12
Top = 2520
Width = 1095
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 0
Left = 1560
TabIndex = 6
Text = "Text1"
Top = 480
Width = 1695
End
Begin VB.ComboBox Combo1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 330
ItemData = "Form2.frx":0000
Left = 1560
List = "Form2.frx":000A
TabIndex = 5
Text = "Combo1"
Top = 1680
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "登记"
Height = 495
Left = 3600
TabIndex = 4
Top = 600
Width = 1095
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 1
Left = 1560
TabIndex = 3
Text = "Text1"
Top = 1080
Width = 1695
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 2
Left = 1560
TabIndex = 2
Text = "Text1"
Top = 2400
Width = 1695
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 3
Left = 1560
TabIndex = 1
Text = "Text1"
Top = 3000
Width = 1695
End
Begin VB.Label Label1
Caption = "学号:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 11
Top = 600
Width = 855
End
Begin VB.Label Label2
Caption = "姓名:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 10
Top = 1080
Width = 855
End
Begin VB.Label Label3
Caption = "性别:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 9
Top = 1680
Width = 855
End
Begin VB.Label Label4
Caption = "班级编号:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 8
Top = 2400
Width = 1215
End
Begin VB.Label Label5
Caption = "学院编号:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 7
Top = 3000
Width = 1215
End
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim DBConn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SqlText As String
Dim s1 As String
Dim s2 As String
Set DBConn = CreateObject("ADODB.Connection")
DBConn.ConnectionString = "DBQ=" + App.Path + "\db1;Driver={Microsoft Access Driver (*.mdb)}"
stu_Id = Text1(0).Text
Stu_Name = Text1(1).Text
cla_Id = Trim(Text1(2).Text)
Stu_Sex = Combo1.ListIndex
dep_Id = Text1(3).Text
s1 = "select stu_Id from 学生信息 where stu_Id='" & stu_Id & "'"
s2 = "select * from 学生信息"
If Trim(Text1(0).Text) = "" Or Trim(Text1(1).Text) = "" Or Trim(Text1(2).Text) = "" Or Trim(Text1(3).Text) = "" Then
MsgBox "录入信息不完整,请重新输入!", vbOKOnly, "提示!"
Else
Set rs = TransactSQL(s1)
If rs.EOF = False Then
MsgBox "该学号学生已经存在!请核对!", vbOKOnly, "提示!"
rs.Close
Else
Set rs = TransactSQL(s2)
rs.AddNew
rs.Fields(0) = Trim(Text1(0).Text)
rs.Fields(1) = Trim(Text1(1).Text)
rs.Fields(2) = Combo1.ListIndex
rs.Fields(3) = Trim(Text1(2).Text)
rs.Fields(4) = Trim(Text1(3).Text)
rs.Update
' SqlText = "Insert Into 学生信息(Stu_Id,Stu_Name,Stu_Sex,cla_Id,dep_Id) " + _
' " values(" + _
' "'" + Text1(0).Text + "', " + _
' "'" + Text1(1).Text + "'," + _
' CStr(Combo1.ListIndex) + ", " + _
' "'" + Text1(2).Text + "', " + _
' "'" + Text1(3).Text + "')"
'DBConn.Execute SqlText
MsgBox "操作成功!!!", vbOKOnly, "提示!"
rs.Close
End If
End If
Init
End Sub
Private Sub Init()
Dim i As Integer
For i = 0 To Text1.Count - 1
Text1(i).Text = ""
Next
Combo1.ListIndex = 0
End Sub
Private Sub Command2_Click()
Form1.Show
Unload Form2
Unload Form3
End Sub
Private Sub Command3_Click()
Dim rs As New ADODB.Recordset
Dim sql As String
sql = "update 学生信息 set stu_Name='" & Text1(1).Text & "'"
sql = sql & ",stu_Sex=" & Combo1.ListIndex & ",cla_Id='" & Text1(2).Text & "'"
sql = sql & ",dep_Id='" & Text1(3).Text & "' where stu_Id='" & Text1(0).Text & "'"
If Trim(Text1(0).Text) = "" Or Trim(Text1(1).Text) = "" Or Trim(Combo1.Text) = "" Or _
Trim(Text1(2).Text) = "" Or Trim(Text1(3).Text) = "" Then
MsgBox "学生信息录入不能为空!", vbOKOnly, "提示!"
Else
TransactSQL (sql)
MsgBox "学生信息修改成功!", vbOKOnly, "提示!"
Unload Me
'Form1.Show
Unload Form3
Form3.command2.Enabled = False
Form3.MSFlexGrid1.Refresh
Form3.Show
End If
End Sub
Private Sub Command4_Click()
Unload Form3
Form3.Show
Unload Me
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim rs As New ADODB.Recordset
'Dim sqlType As String
'sqlType = "select typename from booktype order by typename"
'Set rs = TransactSQL(sqlType)
'While Not rs.EOF
' Combo1.AddItem rs(0)
' rs.MoveNext
'Wend
'rs.Close
'操作选择
If ModifyStFlag2 = True Then
'Dim rs As New ADODB.Recordset
Dim sql As String
sql = "select * from 学生信息 where stu_Id ='" & ModifyStFlag1 & "'"
Set rs = TransactSQL(sql)
Text1(0).Text = rs.Fields(0)
Text1(0).Locked = True ' 使不可改动
Text1(1).Text = rs.Fields(1)
Combo1.ListIndex = rs.Fields(2)
Text1(2).Text = rs.Fields(3)
Text1(3).Text = rs.Fields(4)
ModifyStFlag2 = ModifyStFlag2 Xor True
Command1.Enabled = False
Else
For i = 0 To Text1.Count - 1
Text1(i).Text = ""
Next
Combo1.ListIndex = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -