1个回答
2015-01-07
展开全部
Dim ADB As ADODB.Connection '数据库连接
Dim RST1 As New ADODB.Recordset
Private Sub Command1_Click() '添加操作
ADB.Open
RST1.Open "SELECT * FROM 部门信息表 where 部门编号='" & Text1 & "'", ADB, adOpenKeyset, adLockPessimistic, adCmdText
If RST1.EOF = True Then '如果没有记录就添加记录
RST1.AddNew
RST1.Fields("部门编号") = Text1.Text
RST1.Update
Else
MsgBox "此编号已存在"
End If
RST1.Close
ADB.Close
End Sub
Private Sub Command2_Click()'修改操作
ADB.Open
ADB.Execute "update 部门信息表 set 部门名称 = Text2.Text where 部门编号='" & Text1 & "'"
或
RST1.Open "SELECT * FROM 部门信息表 where 部门编号='" & Text1 & "'", ADB, adOpenKeyset, adLockPessimistic, adCmdText
RST1.Fields("部门名称") = Text2.Text
RST1.Update
RST1.Close
ADB.Close
End Sub
Private Sub Command3_Click() '删除操作
ADB.Open
ADB.Execute "delete * from 部门信息表 where 部门编号='" & Text1 & "'
或
RST1.Open "delete * from 部门信息表 where 部门编号='" & Text1 & "'", ADB, adOpenKeyset, adLockPessimistic, adCmdText
ADB.Close
End Sub
Private Sub Form_Load() '初始化数据库连接
Set ADB = New ADODB.Connection
With ADB
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\中小企业出勤工资管理数据库.mdb"
End With
End Sub
Dim RST1 As New ADODB.Recordset
Private Sub Command1_Click() '添加操作
ADB.Open
RST1.Open "SELECT * FROM 部门信息表 where 部门编号='" & Text1 & "'", ADB, adOpenKeyset, adLockPessimistic, adCmdText
If RST1.EOF = True Then '如果没有记录就添加记录
RST1.AddNew
RST1.Fields("部门编号") = Text1.Text
RST1.Update
Else
MsgBox "此编号已存在"
End If
RST1.Close
ADB.Close
End Sub
Private Sub Command2_Click()'修改操作
ADB.Open
ADB.Execute "update 部门信息表 set 部门名称 = Text2.Text where 部门编号='" & Text1 & "'"
或
RST1.Open "SELECT * FROM 部门信息表 where 部门编号='" & Text1 & "'", ADB, adOpenKeyset, adLockPessimistic, adCmdText
RST1.Fields("部门名称") = Text2.Text
RST1.Update
RST1.Close
ADB.Close
End Sub
Private Sub Command3_Click() '删除操作
ADB.Open
ADB.Execute "delete * from 部门信息表 where 部门编号='" & Text1 & "'
或
RST1.Open "delete * from 部门信息表 where 部门编号='" & Text1 & "'", ADB, adOpenKeyset, adLockPessimistic, adCmdText
ADB.Close
End Sub
Private Sub Form_Load() '初始化数据库连接
Set ADB = New ADODB.Connection
With ADB
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\中小企业出勤工资管理数据库.mdb"
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询