网站首页 | 图形处理 | 网页设计 | 编程学习 | 操作系统学习 | 办公软件学习 | 常用软件学习 | 视频教程 | 设计作品欣赏| IT认证 | 设计素材下载 | 常用软件下载


 aspnet三层架构教程


aspnet三层架构教程

三层架构之数据库访问层(VB)

######数据库访问层##########

@#返回一个ADOCN连接对象

@#与C#不同,这里不能关闭连接及释放内存

Public Function GetCN(sDBPath As String) As ADODB.Connection

Const sPro As String = "provider=microsoft.jet.oledb.4.0;data source="

Const sDBPWD As String = ";jet oledb:database password=QQ:48403849"

Dim sDBPath As String

Dim m_cn As ADODB.Connection

Set m_cn = New ADODB.Connection

m_cn.CursorLocation = adUseClient @#客户端游标

If m_cn.State <> adStateClosed Then m_cn.Close

On Error GoTo conerr

m_cn.Open sPro & sDBPath & sDBPWD

Set GetCN = m_cn

Exit Function

conerr:

Set GetCN = Nothing

MsgBox "数据库连接错误", vbCritical

End Function

@#执行一句SQL语句,正确返回 1

Public Function ExcuteSQL(sSQL As String) As Integer

Dim m_cn As New ADODB.Connection

On Error GoTo err

Set m_cn = GetCN(sG_DBPath)

m_cn.Execute sSQL

m_cn.Close

Set m_cn = Nothing

ExcuteSQL = 1

Exit Function

err:

ExcuteSQL = 0

Set m_cn = Nothing

End Function

@#执行一组SQL语句,正确返回1

Public Function ExcuteSQLEX(sSQL() As String) As Integer

@#调用事务处理

Dim m_cn As New ADODB.Connection, i As Integer

If UBound(sSQL) < 0 Then Exit Function

On Error GoTo err

Set m_cn = GetCN(sG_DBPath)

m_cn.BeginTrans

For i = 0 To UBound(sSQL) - 1

m_cn.Execute sSQL(i)

Next i

m_cn.CommitTrans

m_cn.Close

Set m_cn = Nothing

ExcuteSQLEX = 1

Exit Function

err:

ExcuteSQLEX = 0

m_cn.RollbackTrans

m_cn = Nothing

End Function

@#未完,待补充



  • 上一篇教程:
  • 下一篇教程: 没有了

  •  
    推荐

    最新
    · aspnet三层架构教程
    · asp网页设计教程:ASP计数…
    · asp编程教程:将ASP纪录集…
    · asp留言板教程
    · asp语法教程
    · C语言-编程实例-很普通很…
    · C语言-编程实例-三视图的…
    · C语言-编程实例-我编的国…
    · C语言-编程实例-用递归法…
    · C语言-编程实例-C与脚本…

     

    没有任何图片教程



    本站提供大量Photoshop照片处理,语言编程,网页设计制作,windows系统等软件在线实例教程,欢迎你投稿你的设计作品.lhy514251@163.com

    粤ICP备06081596