Office中国论坛/Access中国论坛

标题: 使用ADP进行mdb数据库开发的实现方案 [打印本页]

作者: zhuyiwen    时间: 2013-7-11 10:31
标题: 使用ADP进行mdb数据库开发的实现方案
使用ADP进行mdb数据库开发的实现方案

优点:
1. 不依赖链接表
2. 纯粹使用ADO
3. 可轻松将mdb数据库应用升迁到SQLServer数据库应用
4. 可使用记录集作为报表的数据来源
5. 应用程序中无数据,数据安全容易得到保障
缺点:
1. 编程量相对较大
2. 开发不直观

实现原理:
1. ADO数据库连接的提供者一定是 “Microsoft.Access.OLEDB.10.0”,这样,记录集才能绑定到窗体和报表
2. ADO数据库连接的数据提供者是 “Microsoft.Jet.OLEDB.4.0” 或者 “Microsoft.ACE.OLEDB.12.0” 或者 “Microsoft.ACE.OLEDB.14.0”,即 mdb 数据库的提供者
3. 新建 ADP 时,取消数据库连接,即保证 ADP 处于断开状态, ADP 中无连接字符串。

对ADO进行了一次封装,作为全局的连接对象,放在 modADO 模块中
  1. Option Compare Database
  2. Option Explicit
  3. ' 作者:朱亦文(zhuyiwen)
  4. ' 时间:2013-07-11

  5. Public Const DBFileName = "Data.mdb"
  6. Public Const DBProvider = "Microsoft.Access.OLEDB.10.0"
  7. Public Const DBDataProvider = "Microsoft.Jet.OLEDB.4.0"
  8. Public Const DBPersistSecurityInfo = "False"
  9. Public Const DBCursorLocation = adUseServer

  10. Private m_Conn As ADODB.Connection
  11. Private m_DBErrorNum As Integer
  12. Private m_DBErrorMessage As String

  13. Public Property Get DBErrorNumber() As Integer
  14.     DBErrorNumber = m_DBErrorNum
  15. End Property

  16. Public Property Get DBErrorMessage() As String
  17.     DBErrorMessage = m_DBErrorMessage
  18. End Property

  19. Public Property Get DBConnectionString() As String
  20.     DBConnectionString = _
  21.         "Provider=" & DBProvider & ";" & _
  22.         "Persist Security Info=" & DBPersistSecurityInfo & ";" & _
  23.         "Data Source=" & CurrentProject.Path & "" & DBFileName & ";" & _
  24.         "Data Provider=" & DBDataProvider
  25. End Property

  26. Public Property Get DBConnection() As ADODB.Connection
  27. On Error GoTo err_GetDBConnection
  28.     If m_Conn Is Nothing Then
  29.         Set m_Conn = New ADODB.Connection
  30.         m_Conn.CursorLocation = DBCursorLocation
  31.     End If
  32.    
  33.     If m_Conn.State <> adStateOpen Then
  34.         m_Conn.Open DBConnectionString
  35.     End If
  36.    
  37.     Set DBConnection = m_Conn
  38.     Exit Property
  39.    
  40. err_GetDBConnection:
  41.     m_DBErrorNum = Err.Number
  42.     m_DBErrorMessage = Err.Description
  43.     Err.Clear
  44. End Property

  45. Public Function DBClearError() As Boolean
  46.     m_DBErrorNum = 0
  47.     m_DBErrorMessage = ""
  48.     DBClearError = True
  49. End Function

  50. Public Function DBCloseConnection() As Boolean
  51. On Error GoTo err_DBCloseConnection
  52.     If m_Conn Is Nothing Then
  53.         DBCloseConnection = True
  54.     End If
  55.    
  56.     If m_Conn.State <> adStateClosed Then
  57.         m_Conn.Close
  58.     End If
  59.    
  60.     Set m_Conn = Nothing
  61.     DBCloseConnection = True
  62.    
  63.     Exit Function
  64.    
  65. err_DBCloseConnection:
  66.     m_DBErrorNum = Err.Number
  67.     m_DBErrorMessage = Err.Description
  68.     Err.Clear
  69. End Function
复制代码
这样的好处,DBConnection 就相当于CurrentProject.Connection,便于程序移植。

[attach]52151[/attach]
[attach]52152[/attach]



作者: andymark    时间: 2013-7-11 10:34
顶 一个
作者: admin    时间: 2013-7-11 10:35
先下手为强
作者: gdjdyyj    时间: 2013-7-11 10:37
学习!
作者: admin    时间: 2013-7-11 10:38
老朱,能实现报表了?
作者: zhuyiwen    时间: 2013-7-11 10:46
示例就是报表
作者: admin    时间: 2013-7-11 11:39
good!
作者: yanwei82123300    时间: 2013-7-11 13:02
先下手为强
作者: zhao123dq    时间: 2013-7-11 21:12
非常厉害              
作者: 月光如水    时间: 2013-7-11 21:14
谢谢分享!
作者: 岭南王子    时间: 2013-7-11 21:18
顶一个
作者: slyz974    时间: 2013-7-11 22:50
谢谢分享
作者: xie62    时间: 2013-7-12 17:32
谢谢分享!
作者: chaosheng    时间: 2013-7-13 20:52
感谢分享,学习
作者: heqing3000    时间: 2013-7-15 07:36
很好!顶一下。
作者: t小宝    时间: 2013-7-16 21:44
Access2013竟然把adp砍掉,绝情呵...
作者: zhuyiwen    时间: 2013-7-17 03:09
是啊,它把纯应用程序的开发方式砍了,呵呵
作者: linlancxh    时间: 2013-7-17 23:01
顶一下
作者: chenwine    时间: 2013-10-12 13:48
什么时封装起来,供下载学习
作者: xinrenq    时间: 2013-10-12 15:55
还是用MDB方式用ADO吧,2013都砍ADP。
作者: smileyoufu    时间: 2013-10-13 23:47
朱总的作品,都是好东西
作者: guzhonghua26    时间: 2013-10-16 22:29
超赞。顶一个。
作者: yy2000    时间: 2013-10-17 08:12
学习!
作者: netguestcn    时间: 2013-10-17 19:05
向老乡学习、向老乡致敬!
作者: sxb2007    时间: 2013-10-30 09:00

谢谢分享!
作者: leonshi    时间: 2013-11-3 11:21
见识了access新的思路
作者: 网络蜘蛛    时间: 2013-11-10 09:23
正在学ADP。
作者: xjb_test    时间: 2013-11-25 13:16
顶 一个
作者: alonet    时间: 2013-11-30 20:11
看看

作者: sql999    时间: 2014-1-26 10:47
学习
作者: tzh1600    时间: 2014-1-26 11:26
学习
作者: 董秋    时间: 2014-3-27 15:28
学习学习
作者: lshstruc    时间: 2014-3-29 16:54
学习一下
作者: zpy2    时间: 2014-6-25 07:19
谢谢了!!!
作者: 63889657    时间: 2014-8-11 16:57
谢谢 我想查看隐藏的内容
作者: 候鸟    时间: 2015-1-11 13:36
XUEXI
作者: joshey    时间: 2015-1-20 17:07
正在学习,感谢朱老师的分享。
作者: zhao__feng    时间: 2015-1-21 19:17

谢谢分享!
作者: hunrybecky    时间: 2015-5-30 16:20
以前也研究ADP,现在基本使用王站的平台。即使不能异地了,
作者: 764300778    时间: 2015-5-31 11:24
EEEE
作者: a30088    时间: 2015-6-4 19:03

谢谢分享!
作者: Sky_    时间: 2015-12-13 17:03
顶 一个
作者: jlf001    时间: 2016-4-10 15:18
学习
作者: 27622259    时间: 2016-4-11 21:55
GOOD
作者: 天涯沦落20131    时间: 2018-5-17 04:29
111111111
作者: 六月雪    时间: 2018-5-19 03:43
哦哦哦哦哦哦哦
作者: NGQ208208    时间: 2018-8-2 22:55
谢谢分享
作者: VENUSSWF    时间: 2018-8-3 09:10
学习学习
作者: BushLI    时间: 2018-8-5 12:25
谢谢老师
作者: BushLI    时间: 2018-8-5 12:28
朱老师,看了您的视频讲课,谢谢。我做的access 数据库,因多人操作,打开有些慢,采用的事连接表型式,是不是要该为ADP,升迁啊?
但access2013版之后不支持ADP了,学习没信心了。
作者: jiutianxingchen    时间: 2018-8-10 09:48
朱总好
作者: jiutianxingchen    时间: 2018-8-10 09:49
谢谢
作者: euilo    时间: 2018-9-30 22:53
学习学习
作者: 灰太郎    时间: 2018-10-7 08:52
fffffdddfffddff
作者: 灰太郎    时间: 2018-10-7 08:52
fffffdddfffddff
作者: 灰太郎    时间: 2018-10-7 08:52
fffffffffcfg
作者: 灰太郎    时间: 2018-10-7 08:53
ggffffff




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3