📄 form1.frm
字号:
Height = 495
Left = 8280
TabIndex = 11
Top = 2880
Width = 1215
End
Begin VB.CommandButton Command3
Caption = "删除"
Height = 495
Left = 8280
TabIndex = 10
Top = 2000
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "保存修改"
Height = 495
Left = 8280
TabIndex = 9
Top = 1080
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 495
Left = 8280
TabIndex = 8
Top = 240
Width = 1215
End
Begin VB.TextBox txtAdd
Height = 315
Left = 1080
TabIndex = 7
Top = 3000
Width = 5655
End
Begin VB.TextBox txtStudentId
Height = 375
Left = 5520
TabIndex = 5
Top = 1042
Width = 1215
End
Begin VB.TextBox txtstudentName
Height = 315
Left = 1110
TabIndex = 2
Top = 240
Width = 1260
End
Begin VB.TextBox txtTel
Height = 315
Left = 1110
TabIndex = 3
Top = 2040
Width = 1260
End
Begin VB.TextBox Text1
Height = 375
Left = 5520
TabIndex = 6
Top = 1920
Width = 1215
End
Begin VB.Label Label10
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "年级班级:"
Height = 180
Left = 4380
TabIndex = 19
Top = 300
Width = 900
End
Begin VB.Label Label4
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "出生日期:"
Height = 180
Left = 4380
TabIndex = 18
Top = 1920
Width = 900
End
Begin VB.Label Label8
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "家庭住址:"
Height = 180
Left = 90
TabIndex = 17
Top = 3000
Width = 900
End
Begin VB.Label Label6
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "联系电话:"
Height = 180
Left = 90
TabIndex = 16
Top = 2040
Width = 1005
End
Begin VB.Label Label3
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "性别:"
Height = 180
Left = 90
TabIndex = 15
Top = 1170
Width = 1005
End
Begin VB.Label Label2
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "姓名:"
Height = 180
Left = 90
TabIndex = 14
Top = 300
Width = 1005
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "学号:"
Height = 180
Left = 4680
TabIndex = 13
Top = 1110
Width = 540
End
End
End
Attribute VB_Name = "usestu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public rs As New ADODB.Recordset
Public rs1 As New ADODB.Recordset
Private Sub Command1_Click()
Dim sq1 As String
On Error GoTo err
con.Open
sql = "select xh from stu where xh='" & txtStudentId.Text & "'"
Set rs = con.Execute(sql)
If rs.BOF Or rs.EOF Then
sq1 = "insert into stu(xm,nb,sex,xh,dh,cs,dz) values('" & txtstudentName.Text & "','" & cboGrade.Text & "','" & Combo1.Text & "','" & txtStudentId.Text & "','" & txtTel.Text & "','" & Text1.Text & "','" & txtAdd.Text & "')"
con.Execute (sq1)
MsgBox "添加成功", vbOKOnly + vbExclamation, "提示"
Unload Me
Else
MsgBox "学号不能重复插入,请重新输入!", vbOKOnly + vbInformation, "提示"
End If
con.Close
Exit Sub
err:
MsgBox "输入错误"
con.Close
End Sub
Private Sub Command2_Click()
On Error GoTo err
con.Open
Dim sq2 As String
sq2 = "select xh from stu where xh='" & txtStudentId.Text & "'"
Set rs1 = con.Execute(sq2)
If txtStudentId.Text = "" Then
MsgBox "请输入学号"
Else
If rs1.BOF Or rs1.EOF Then
MsgBox "该学号不存在,请重新输入!", vbOKOnly + vbInformation, "提示"
Else
sq2 = "update stu set xm='" & txtstudentName.Text & "',nb='" & cboGrade.Text & "',sex='" & Combo1.Text & "',dh='" & txtTel.Text & "',cs='" & Text1.Text & "',dz='" & txtAdd.Text & "'where xh='" & txtStudentId.Text & "'"
con.Execute (sq2)
MsgBox "修改成功", vbOKOnly + vbExclamation, "提示"
Unload Me
End If
End If
con.Close
Exit Sub
err:
MsgBox "输入错误"
con.Close
End Sub
Private Sub Command3_Click()
On Error GoTo err
con.Open
Dim sq As String
If txtStudentId.Text = "" Then
MsgBox "请至少输入所要删除信息的学号"
Else
sq = "delete from stu where xh='" & txtStudentId.Text & "'"
con.Execute (sq)
MsgBox "成功删除", vbOKOnly + vbExclamation, "提示"
Unload Me
con.Close
Exit Sub
err:
MsgBox "输入错误"
End If
con.Close
End Sub
Private Sub Command4_Click()
Unload Me
frmmain.Show
End Sub
Private Sub Command5_Click()
Dim strsql As String
Call st1
con.Open
strsql = "select xh from stu where xh='" & txtid.Text & "'"
Set rs = con.Execute(strsql)
If txtid.Text = "" Then
MsgBox "学号不能为空!", vbOKOnly + vbInformation, "提示"
txtid.SetFocus
con.Close
Exit Sub
Else
If rs.BOF Or rs.EOF Then
MsgBox "没有找到符合条件的记录,请重新输入!", vbOKOnly + vbInformation, "提示"
Else
DataGrid1.Visible = True
strsql = "select * from stu where xh='" & txtid.Text & "' "
'Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.UpdateBatch adAffectAllChapters
txtstudentName.Text = DataGrid1.Columns.Item(0)
Combo1.Text = DataGrid1.Columns.Item(1)
cboGrade.Text = DataGrid1.Columns.Item(2)
txtStudentId.Text = DataGrid1.Columns.Item(3)
txtTel.Text = DataGrid1.Columns.Item(4)
Text1.Text = DataGrid1.Columns.Item(5)
txtAdd.Text = DataGrid1.Columns.Item(6)
End If
End If
con.Close
End Sub
Private Sub DataGrid1_Click()
txtstudentName.Text = DataGrid1.Columns.Item(0)
Combo1.Text = DataGrid1.Columns.Item(1)
cboGrade.Text = DataGrid1.Columns.Item(2)
txtStudentId.Text = DataGrid1.Columns.Item(3)
txtTel.Text = DataGrid1.Columns.Item(4)
Text1.Text = DataGrid1.Columns.Item(5)
txtAdd.Text = DataGrid1.Columns.Item(6)
End Sub
Private Sub Form_Activate()
Adodc1.RecordSource = "select * from stu"
Adodc1.Refresh
End Sub
Private Sub Form_Load()
Call st1
Adodc1.ConnectionString = ("Provider=SQLOLEDB;User ID=" & a & ";PWD=" & b & ";Initial Catalog=student;Data Source=" & d & "")
'Adodc1.Password = frmLogin.mm.Text
'Adodc1.UserName = frmLogin.yhm.Text
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -