格式化字符函數

原始位置﹕http://dev.csdn.net/author/fanpingli/1742be883708457999b0ad569b82c878.html

Function Q(ByVal SqlVariable As Variant) As String
'-----------------------------------------
'        Notes: Useful in creating properly formatted SQL statements
'        Usage: sql="select * from table where name= " & Q(vntName)
'        ??版本格式化适用于Access的?量,若支持其它?据?或?需要?其?行修改
'-----------------------------------------

On Error GoTo ErrTrap
Q = SqlVariable
'format the string
    Select Case VarType(SqlVariable)
        Case vbNull, vbEmpty
                Q = "NULL"
                Case vbString
                Q = "'" & Replace(SqlVariable, "'", "''") & "'"
                'date variable
        Case vbDate
            'format and enclose in pounds signs for Access
            Q = "'" & Format$(SqlVariable, "general date") & "'"
            'otherwise treat as numeric
        Case Else
            On Error Resume Next
            Q = CStr(SqlVariable)
            If Err.Number <> 0 Then Q = SqlVariable
    End Select
    Exit Function

ErrTrap:
 On Error GoTo 0
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值