VB数据库编程实现添加、查询、修改、删除

前端之家收集整理的这篇文章主要介绍了VB数据库编程实现添加、查询、修改、删除前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub Command1_Click() Form10.Hide Form4.Show End Sub Private Sub Command10_Click() For i = 0 To 7 If Text1(i).Text <> "" Then Exit For End If Next i If i = 8 Then MsgBox ("不能保存空记录!") Text1(0).SetFocus Exit Sub End If If Text1(0).Text = "" Then MsgBox ("年级不能为空") Text1(0).SetFocus Exit Sub End If If Text1(1).Text = "" Then MsgBox ("姓名不能为空") Text1(1).SetFocus Exit Sub End If If Text1(2).Text = "" Then MsgBox ("专业不能为空") Text1(2).SetFocus Exit Sub End If If Text1(3).Text = "" Then MsgBox ("时间不能为空") Text1(3).SetFocus Exit Sub End If Adodc1.Recordset.Update Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False For i = 0 To 7 Text1(i).Enabled = False Next i MsgBox ("保存成功") End Sub Private Sub Command11_Click() If Adodc1.Recordset.RecordCount = 0 Then Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False Exit Sub End If Adodc1.Recordset.CancelUpdate Adodc1.Refresh For i = 0 To 7 Text1(i).Enabled = False Next i Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False End Sub Private Sub Command12_Click() Set DataGrid1.DataSource = Adodc1 DataGrid1.Visible = True End Sub Private Sub Command2_Click() If Adodc1.Recordset.RecordCount = 0 Then Exit Sub End If Adodc1.Recordset.MoveFirst Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False End Sub Private Sub Command3_Click() If Adodc1.Recordset.RecordCount = 0 Then Exit Sub End If Adodc1.Recordset.MovePrevIoUs If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False End Sub Private Sub Command4_Click() If Adodc1.Recordset.RecordCount = 0 Then Exit Sub End If Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False End Sub Private Sub Command5_Click() If Adodc1.Recordset.RecordCount = 0 Then Exit Sub End If Adodc1.Recordset.MoveLast Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = False Command11.Enabled = False End Sub Private Sub Command6_Click() Adodc1.Recordset.AddNew For i = 0 To 7 Text1(i).Enabled = True Text1(i).Text = "" Text1(0).SetFocus Next i Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Command5.Enabled = False Command6.Enabled = False Command7.Enabled = False Command8.Enabled = False Command9.Enabled = False Command10.Enabled = True Command11.Enabled = True End Sub Private Sub Command7_Click() If Adodc1.Recordset.RecordCount = 0 Then MsgBox ("没有要删除的记录") Exit Sub End If Dim str As String str = MsgBox("真的要删除此记录么?",vbYesNo) If str = vbYes Then Adodc1.Recordset.Delete Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast End If End Sub Private Sub Command8_Click() 'On Error Resume Next Dim str As String 'Adodc1.CursorType = adOpenDynamic str = InputBox("请输入社员年级","请查找") Adodc1.CommandType = adCmdText Adodc1.RecordSource = "SELECT * FROM 社员 WHERE 年级= '" & str & " ' " Adodc1.Refresh If Adodc1.Recordset.EOF Then Adodc1.CommandType = adCmdText Adodc1.RecordSource = " select * from 社员 " Adodc1.Refresh MsgBox "没有此社员","查找" End If ' If 'Dim mzy As String 'mzy = InputBox("请输入年级号","请查找") 'Adodc1.CommandType = adCmdText 'Adodc1.RecordSource = "Select * From 社员 Where 年级= '" & mzy & " '" 'Adodc1.Refresh 'If Adodc1.Recordset.EOF Then 'MsgBox "无此读者号!","提示" End Sub Private Sub Command9_Click() Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Command5.Enabled = False Command6.Enabled = False Command7.Enabled = False Command8.Enabled = False Command9.Enabled = False Command10.Enabled = True Command11.Enabled = True If Adodc1.Recordset.RecordCount <> 0 Then For i = 0 To 7 Text1(i).Enabled = True Next i Else MsgBox ("没有要修改的记录") End If End Sub Private Sub Form_Load() For i = 0 To 7 Text1(i).Enabled = False Next i Command10.Enabled = False Command11.Enabled = False End Sub Private Sub Text2_Change() End Sub 原文链接:https://www.f2er.com/vb/264428.html

猜你在找的VB相关文章