【#第一文档网# 导语】以下是®第一文档网的小编为您整理的《代码vb》,欢迎阅读!
Private Sub Command1_Click() '添加 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\ljdate.mdb;Persist Security Info=False" Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select * from 零件信息表 where 零件代码= '" & Text1.Text & "' " Adodc1.Refresh If Len(Text1.Text) = 0 Then MsgBox "零件号不能为空", 48, "无法保存" Exit Sub End If If Len(Text2.Text) = 0 Then MsgBox "零件名称不能为空", 48, "无法保存" Exit Sub End If If Len(Text6.Text) = 0 Then MsgBox "库存量不能为空", 48, "无法保存" Exit Sub End If Adodc1.Refresh Adodc1.Recordset.AddNew Adodc1.Recordset.Fields("零件代码") = Text1.Text Adodc1.Recordset.Fields("名称") = Text2.Text Adodc1.Recordset.Fields("库存量") = Text6.Text MsgBox "保存成功", 48, "提示" Adodc1.Recordset.Update Text1.Text = "" Text2.Text = "" Text6.Text = "" End Sub --------------------------------------------------------------------------------------------------------------------------------- Private Sub Command3_Click() '查询 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\ljdate.mdb;Persist Security Info=False" Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select * from 零件信息表 where 零件代码= '" & Text3.Text & "' " Adodc1.Refresh If Not Adodc1.Recordset.EOF Then Text4.Text = Adodc1.Recordset.Fields("名称") Text5.Text = Adodc1.Recordset.Fields("库存量") Text3.Enabled = False Text4.Enabled = False Text5.Enabled = False Else MsgBox "没有这个零件信息,请重新输入正确的零件号", 48, "错误提示" End If End Sub -------------------------------------------------------------------------------------------------------------------------------- Private Sub Command5_Click() '删除 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\ljdate.mdb;Persist Security Info=False" Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select * from 零件信息表表 where 零件代码= '" & Text3.Text & "' " Adodc1.Refresh If Not Adodc1.Recordset.EOF Then sel = MsgBox("确认要删该零件信息吗?", vbQuestion + vbYesNo) If sel = vbYes Then Adodc1.Recordset.Delete MsgBox "已删除", 48, "提示" Text3.Text = "" Text4.Text = "" Text5.Text = "" Else End If MsgBox "该零件信息不存在", vbInformation End If End Sub --------------------------------------------------------------------------------------------------------------------------------- Private Sub Command6_Click() '修改 Text3.Enabled = False Text4.Enabled = True Text5.Enabled = True Text4.SetFocus Text4.SelStart = 0 Text4.SelLength = Len(Text4.Text) Text5.SetFocus Text5.SelStart = 0 Text5.SelLength = Len(Text5.Text) End Sub --------------------------------------------------------------------------------------------------------------------------------- Private Sub Command7_Click() '保存 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\ljdate.mdb;Persist Security Info=False" Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select * from 零件信息表 where 零件代码= '" & Text3.Text & "' " Adodc1.Refresh Adodc1.Recordset.Fields("名称") = Text4.Text Adodc1.Recordset.Fields("库存量") = Text5.Text MsgBox "保存成功", 48, "提示" Adodc1.Recordset.Update Text3.Text = "" Text4.Text = "" Text5.Text = "" End Sub Private Sub Command8_Click() sel = MsgBox("确认要退出吗?", vbQuestion + vbYesNo) If sel = vbYes Then Me.Hide End If End Sub 本文来源:https://www.dywdw.cn/793d90ff4afe04a1b071de80.html