VB6.0

Public Function GetConnStr() As String
    Dim ConnString As String
    ConnString = "Provider = SQLOLEDB.1;Database=IHURALibrary;server=.;uid=Lindy;pwd=sa!12345;"
    GetConnStr = ConnString
End Function

Public Function OpenConn(ByRef Conn As ADODB.Connection) As Boolean
    Set Conn = New ADODB.Connection
    On Error GoTo ErrorHandle
        Conn.Open GetConnStr
        OpenConn = True
        Exit Function
ErrorHandle:
        MsgBox "Á¬½ÓÊý¾Ý¿âʧ°Ü£¡ÇëÖØÐÂÁ¬½Ó"
        OpenConn = False
        Exit Function
End Function

Public Function ExecuteSQL(ByVal SQL As String, ByRef msg As String) As String
    Dim Conn As ADODB.Connection
    On Error GoTo ErrorHandle
        If OpenConn(Conn) Then
            Conn.Execute SQL
            msg = "²Ù×÷Ö´Ðгɹ¦£¡"
        End If
        ExecuteSQL = ""
        Exit Function
ErrorHandle:
        msg = "Ö´ÐдíÎó£º" & Err.Description
        ExecuteSQL = ""
        Set Conn = Nothing
        Exit Function
End Function

Public Function SelectSQL(ByVal SQL As String, ByRef msg As String) As ADODB.Recordset
    Dim Conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sTokens() As String
    On Error GoTo ErrorHandle
    sTokens = Split(SQL)
    If InStr("SELECT", UCase((sTokens(0)))) Then
        If OpenConn(Conn) Then
            Set rs = New ADODB.Recordset
            rs.CursorLocation = adUseClient
            rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic
            Set SelectSQL = rs
            msg = "²éѯµ½" & rs.RecordCount & " Ìõ¼Ç¼!"
        End If
    Else
        msg = "SQLÓï¾äÓÐÓï:" & SQL
    End If
ErrorHandle:
    msg = "²éѯ´íÎó£º" & Err.Description
    Set rs = Nothing
    Set Conn = Nothing
    Exit Function
End Function

Public Function BatchSelectSQL(ByVal SQL As String, ByRef msg As String) As ADODB.Recordset
    Dim Conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sTokens() As String
    On Error GoTo ErrorHandle
    sTokens = Split(SQL)
    If InStr("SELECT", UCase((sTokens(0)))) Then
        If OpenConn(Conn) Then
            Set rs = New ADODB.Recordset
            rs.CursorLocation = adUseClient
            rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockBatchOptimistic
            Set SelectSQL = rs
            msg = "²éѯµ½" & rs.RecordCount & " Ìõ¼Ç¼!"
        End If
    Else
        msg = "SQLÓï¾äÓÐÓï:" & SQL
    End If
ErrorHandle:
    msg = "²éѯ´íÎó£º" & Err.Description
    Err.Description
    Set rs = Nothing
    Set Conn = Noting
    Exit Function
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值