如题,在VB6.0中应该怎样使用ADO Errors collection?请尽量用代码说明。
不胜感激!

解决方案 »

  1.   

    定义Errors对象变量,具体没有做过。
      

  2.   

    Option ExplicitSub Main()
        Dim cn As ADODB.Connection
        Dim adErr As ADODB.Error
        
        On Error GoTo ErrHandler    Set cn = New ADODB.Connection
        cn.Open ...
        cn.Execute "SELECT"ExitEntry:
        Exit Sub
    ErrHandler:
        Debug.Print "VB Err: ", Err.Number, Err.Description    Debug.Print "ADO Error:"
        For Each adErr In cn.Errors
            Debug.Print adErr.Number, adErr.Description
        Next
        Resume ExitEntry
    End Sub
      

  3.   

    ADO Error Codes
    In addition to the provider errors that are described in the Error object and Errors collection, ADO itself can return errors to the exception-handling mechanism of your run-time environment. Use your programming language's error trapping mechanism, such as the On Error statement in Microsoft® Visual Basic®, to trap and handle the following errors. Both decimal and hexadecimal error code values are shown. Constant Name Number Description 
     
    adErrInvalidArgument 3001
    0x800A0BB9 
     The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another. 
    adErrNoCurrentRecord 3021
    0x800A0BCD 
     Either BOF or EOF is True, or the current record has been deleted; the operation requested by the application requires a current record. 
    adErrIllegalOperation 3219
    0x800A0C93 
     The operation requested by the application is not allowed in this context. 
    adErrInTransaction 3246
    0x800A0CAE 
     The application may not explicitly close a Connection object while in the middle of a transaction. 
    adErrFeatureNotAvailable 3251
    0x800A0CB3 
     The operation requested by the application is not supported by the provider. 
    adErrItemNotFound 3265
    0x800A0CC1 
     ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application. 
    adErrObjectInCollection 3367
    0x800A0D27 
     Can't append. Object already in collection. 
    adErrObjectNotSet 3420
    0x800A0D5C 
     The object referenced by the application no longer points to a valid object. 
    adErrDataConversion 3421
    0x800A0D5D 
     The application is using a value of the wrong type for the current operation. 
    adErrObjectClosed 3704
    0x800A0E78 
     The operation requested by the application is not allowed if the object is closed. 
    adErrObjectOpen 3705
    0x800A0E79 
     The operation requested by the application is not allowed if the object is open. 
    adErrProviderNotFound 3706
    0x800A0E7A 
     ADO could not find the specified provider. 
    adErrBoundToCommand 3707
    0x800A0E7B 
     The application cannot change the ActiveConnection property of a Recordset object with a Command object as its source. 
    adErrInvalidParamInfo 3708
    0x800A0E7C 
     The application has improperly defined a Parameter object. 
    adErrInvalidConnection 3709
    0x800A0E7D 
     The application requested an operation on an object with a reference to a closed or invalid Connection object 
      

  4.   

    这个对象一般用在ADO的各个事件中返回执行过程中的一些错误.它的属性基本都是只读的,所以你如果不用ADO的事件的话,这玩意儿基本没用,不如直接用VB的ERR对象.