您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
一个普通的数据库例子源源程序
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:06:54
nn, adOpenForwardOnly, adLockReadOnly)
     ' Else the connection is closed
     Else
     ' Set the ConnectionString
     Call SetConnectionString(csConnectionString)
     ' If atempt To open connection succeeded
     If DBConnOpen() Then
     ' Acquire data With connection object
     Call loRS.Open(asSQL, oConn, adOpenForwardOnly, adLockReadOnly)
     ' Return connection object To closed state
     Call DBConnClose()
     End If ' DBConnOpen()
     End If ' aoConn.State = adStateOpen
     ' Else active connection is the ConnectionString
     Else
     ' Acquire data With ConnectionString
     Call loRS.Open(asSQL, sCONNECTION_STRING, adOpenForwardOnly, adLockReadOnly)
     End If ' IsObject(oConn)
     ' If errors occured
     If Err Then
     response.write "<HR color=red>" & err.description & "<HR color=red>" & asSQL & "<HR
color=red>"
     ' Clear the Error
     Err.Clear
     ' If the recorset is open
     If loRS.State = adStateOpen Then
     ' Close the recorset
     loRS.Close
     End If ' loRS.State = adStateOpen
     ' Release Recordset from memory
     Set loRS = Nothing
     ' Return negative results
     SetData = False
     ' Exit Routine
     Exit Function
     End If ' Err
     ' Return positve results
     SetData = True
     ' If data was found
     If Not loRS.EOF Then
     ' Pull data into an array
     avDataAry = loRS.GetRows
     End If ' Not loRS.EOF
     ' Close Recordset
     loRS.Close
     ' Release object from memory
     Set loRS = Nothing
    End Function ' SetData
    '---------------------------------------
    '     ----------------------------------------
    '     
    ' SQL Preperations are used to prepare v
    '     ariables for SQL Queries. If
    ' invalid data is passed to these routin
    '     es, NULL values or Default Data
    ' is returned to keep your SQL Queries f
    '     rom breaking from users breaking
    ' datatype rules.
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_s(ByVal asExpression, ByRef anMaxLength)
     ' If maximum length is defined
     If anMaxLength > 0 Then
     ' Trim expression To maximum length
     asExpression = Left(asExpression, anMaxLength)
     End If ' anMaxLength > 0
     ' Double quote SQL quote characters
     asExpression = Replace(asExpression, "'", "'")
     ' If Expression is Empty
     If asExpression = "" Then
     ' Return a NULL value
     SQLPrep_s = "NULL"
     ' Else expression is Not empty
     Else
     ' Return quoted expression
     SQLPrep_s = "'" & asExpression & "'"
     End If ' asExpression
    End Function ' SQLPrep_s
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_n(ByVal anExpression)
     ' If expression numeric
     If IsNumeric(anExpression) And Not anExpression = "" Then
     ' Return number
     SQLPrep_n = anExpression
     ' Else expression Not numeric
     Else
     ' Return NULL
     SQLPrep_n = "NULL"
     End If ' IsNumeric(anExpression) And Not anExpression = ""
    End Function ' SQLPrep_n
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_b(ByVal abExpression, ByRef abDefault)
     ' Declare Database Constants
     Const lbTRUE = -1 '1 = SQL, -1 = Access
     Const lbFALSE = 0
     Dim lbResult ' Result To be passed back
     ' Prepare For any errors that may occur
     On Error Resume Next
     ' If expression Not provided
     If abExpression = "" Then
     ' Set expression To default value
     abExpression = abDefault
     End If ' abExpression = ""
     ' Attempt To convert expression
     lbResult = CBool(abExpression)
     ' If Err Occured
     If Err Then
     ' Clear the Error
     Err.Clear
     ' Determine action based on Expression
     Select Case LCase(abExpression)
     ' True expressions
     Case "yes", "on", "true", "-1", "1"
     lbResult = True
     ' False expressions
     Case "no", "off", "false", "0"
     lbResult = False
     ' Unknown expression
     Case Else
     lbResult = abDefault
     End Select ' LCase(abExpression)
     End If ' Err
     ' If result is True
     If lbResult Then
     ' Return True
     SQLPrep_b = lbTRUE
     ' Else Result is False
     Else
     ' Return False
     SQLPrep_b = lbFALSE
     End If ' lbResult
    End Function ' SQLPrep_b
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_d(ByRef adExpression)
     ' If Expression valid Date
     If IsDate(adExpression) Then
     ' Return Date
     'SQLPrep_d = "'" & adExpression & "'" ' SQL Database
     SQLPrep_d = "#" & adExpression & "#" ' Access Database
     ' Else Expression Not valid Date
     Else
     ' Return NULL
     SQLPrep_d = "NULL"
     End If ' IsDate(adExpression)
    End Function ' SQLPrep_d
    '---------------------------------------
    '     ----------------------------------------
    

上一页  [1] [2] [3] [4] 下一页


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |