📄 frmaddreader.frm
字号:
VERSION 5.00
Begin VB.Form frmAddReader
Caption = "添加读者"
ClientHeight = 2505
ClientLeft = 60
ClientTop = 345
ClientWidth = 4590
LinkTopic = "Form1"
ScaleHeight = 2505
ScaleWidth = 4590
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command2
Caption = "返回(&C)"
Height = 375
Left = 2280
TabIndex = 7
Top = 2040
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "添加(&A)"
Height = 375
Left = 840
TabIndex = 6
Top = 2040
Width = 1095
End
Begin VB.Frame Frame1
Caption = "读者基本信息"
Height = 1695
Left = 120
TabIndex = 0
Top = 120
Width = 4335
Begin VB.ComboBox cmbSex
Height = 315
Left = 2880
TabIndex = 10
Text = "Combo1"
Top = 240
Width = 1215
End
Begin VB.TextBox txtClass
Height = 315
Left = 840
TabIndex = 9
Text = "Text4"
Top = 1200
Width = 3135
End
Begin VB.TextBox txtAge
Height = 315
Left = 840
TabIndex = 5
Text = "Text3"
Top = 720
Width = 1215
End
Begin VB.TextBox txtName
Height = 315
Left = 840
TabIndex = 2
Text = "Text1"
Top = 240
Width = 1455
End
Begin VB.Label Label4
Caption = "班级:"
Height = 255
Left = 240
TabIndex = 8
Top = 1320
Width = 855
End
Begin VB.Label Label3
Caption = "年龄:"
Height = 255
Left = 240
TabIndex = 4
Top = 840
Width = 615
End
Begin VB.Label Label2
Caption = "性别:"
Height = 255
Left = 2400
TabIndex = 3
Top = 360
Width = 615
End
Begin VB.Label Label1
Caption = "姓名:"
Height = 255
Left = 240
TabIndex = 1
Top = 360
Width = 735
End
End
End
Attribute VB_Name = "frmAddReader"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim sql As String
Private Sub Command1_Click()
sql = "INSERT INTO readers(name,sex,age,class) VALUES('" & txtName.Text & _
"','" & cmbSex.Text & "'," & txtAge.Text & ",'" & txtClass.Text & "')"
cmd.CommandText = sql
rs.Open cmd, , adOpenKeyset
MsgBox "添加完毕!!"
resetForm
End Sub
Private Sub Command2_Click()
Me.Visible = False
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
resetForm
'使用Connection对象与具体的数据库文件相连接
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db\library.mdb"
'每个Command必须与一个Connection对象连接
Set cmd.ActiveConnection = conn
'设置命令的类型是使用SQL语句
cmd.CommandType = adCmdText
End Sub
Private Sub resetForm()
txtName.Text = ""
txtAge.Text = ""
txtClass.Text = ""
cmbSex.AddItem "男"
cmbSex.AddItem "女"
cmbSex.Text = ""
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -