ADODB.Command执行总是返回错误的值,即-1

时间:2013-06-04 04:18:17

标签: vb6 sybase adodb sqlcommand

我无法找到受以下查询影响的记录。在成功事务和失败事务中,它返回-1值。

Public Function fnModifyRecord() As Boolean

    Dim conTran As New ADODB.Connection
    Dim comTran As New ADODB.Command
    conTran.Errors.Clear
    On Error Resume Next
    conTran.Open "Provider=MSDataShape;ODBC;Database=" & strDatabase & ";UID=" & strUID & ";PWD=" & strPWD & ";DSN=" & strDSN & ""

    If conTran.Errors.Count > 0 Then
        MsgBox "FAILED TO CONNECT TO SERVER"
        interr = 0
        Do Until interr = conTran.Errors.Count
            MsgBox conTran.Errors.Item(interr).Description, vbCritical, strMsg
            interr = interr + 1
        Loop
        fnModifyRecord = False
        Exit Function
    End If

    '/***** Begin modification
    conTran.BeginTrans
    comTran.ActiveConnection = conTran
    comTran.CommandType = adCmdText
    comTran.CommandText = "Update Department set EmpName = 'Preeti' where EmpCode = 1101 and DeptName ='IT'"
    conTran.Errors.Clear
    On Error Resume Next

    comTran.Execute

    If conTran.Errors.Count > 0 Then
        conTran.RollbackTrans
        interr = 0
        Do Until interr = conTran.Errors.Count
            MsgBox conTran.Errors.Item(interr).Description, vbCritical, strMsg
            interr = interr + 1
        Loop
        conTran.Close
        fnModifyRecord = False
        Exit Function
    End If

    comTran.CommandText ="update Emptbl set EmpName ='Preeti' where EmpCode = 1101"

    conTran.Errors.Clear
    On Error Resume Next
    Dim r As Integer
    comTran.Execute r
    '/***** check the status of r it should be 1
    If r <> 1 Then
        MsgBox "ERROR ---- RECORD DID NOT GET UPDATED"
        conTran.RollbackTrans
        If conTran.Errors.Count > 0 Then
        interr = 0
        Do Until interr = conTran.Errors.Count
            MsgBox conTran.Errors.Item(interr).Description, vbCritical, strMsg
            interr = interr + 1
        Loop
        conTran.Close
        fnModifyRecord = False
        If conTran.State = 1 Then
                    conTran.Close
                    Set conTran = Nothing
                End If

        Exit Function
        End If
    End If

    If conTran.Errors.Count > 0 Then
        conTran.RollbackTrans
        interr = 0
        Do Until interr = conTran.Errors.Count
            MsgBox conTran.Errors.Item(interr).Description, vbCritical, strMsg
            interr = interr + 1
        Loop
        conTran.Close
        fnModifyRecord = False
        Exit Function
    End If

    conTran.CommitTrans
    conTran.Close
    fnModifyRecord = True
    Exit Function
End Function

注意:最近我们将数据库(Sybase 15)的页面大小从2K更新为4K。

0 个答案:

没有答案