⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employees.cls

📁 vb与access数据库的操作实例
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Employees"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public EmpId As Integer          '员工编号,设置为主键
Public EmpName As String         '员工姓名
Public Sex As String             '员工性别
Public Title As String           '员工职务
Public Age As Integer            '年龄
Public Office_phone As String    '办公电话
Public Mobile_phone As String    '移动电话
Public Sallary As Single         '工资
Public DepId As Integer          '所在部门编号

'初始化成员变量
Public Sub Init()
  EmpId = ""
  EmpName = ""
  Sex = ""
  Title = ""
  Age = 0
  Office_phone = ""
  Mobile_phone = ""
  Sallary = 0
  DepId = 0
End Sub

'删除数据
Public Sub Delete(ByVal TmpId As Integer)
  Dim SQLstmt As String    '存放SQL语句的字符串
  '执行DELETE语句,删除EmpId等于TmpId的记录
  SQLstmt = "DELETE FROM Employees WHERE EmpId=" + Trim(TmpId)
  SQLExt (SQLstmt)
End Sub

Public Sub Insert()
  Dim SQLstmt As String    '存放SQL语句的字符串
  '执行INSERT语句
  SQLstmt = "INSERT INTO Employees (EmpName, Sex, Title, Age, Office_phone," _
          + " Mobile_phone, Sallary, DepId) VALUES('" + Trim(EmpName) + "','" _
          + Trim(Sex) + "','" + Trim(Title) + "'," + Trim(Age) + ",'" _
          + Trim(Office_phone) + "','" + Trim(Mobile_phone) + "'," _
          + Trim(Sallary) + "," + Trim(DepId) + ")"
  SQLExt (SQLstmt)
End Sub

Public Sub Update(ByVal OriId As String)
  Dim SQLstmt As String    '存放SQL语句的字符串
  
  '执行SQL语句
  SQLstmt = "UPDATE Employees SET EmpName='" + Trim(EmpName) + "', Sex='" _
          + Trim(Sex) + "', Title='" + Trim(Title) + "', Age=" + Trim(Age) _
          + ", Office_phone ='" + Trim(Office_phone) + "', Mobile_phone='" _
          + Trim(Mobile_phone) + "', Sallary=" + Trim(Sallary) + ", DepId=" _
          + Trim(DepId) + " WHERE EmpId=" + Trim(OriId)
  SQLExt (SQLstmt)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -