引用:http://topic.csdn.net/t/20020614/13/803423.html
问:Set adoSchemaRecordsetX = adoConnectionX.OpenSchema(adSchemaTables, Array(Empty, Empty, strTableName, "Table")),此句如何理解呢?Array数组的作用?

解决方案 »

  1.   

    OpenSchema MethodObtains database schema information from the provider.Syntax
    --------------------------------------------------------------------------------Copy
     
    Set recordset = connection.OpenSchema(QueryType, Criteria, SchemaID)
    Return Value
    --------------------------------------------------------------------------------Returns a Recordset object that contains schema information. The Recordset will be opened as a read-only, static cursor. The QueryType determines what columns appear in the Recordset.Parameters
    --------------------------------------------------------------------------------QueryType 
    Any SchemaEnum value that represents the type of schema query to run.Criteria 
    Optional. An array of query constraints for each QueryType option, as listed in SchemaEnum.
    SchemaID 
    The GUID for a provider-schema query not defined by the OLE DB specification. This parameter is required if QueryType is set to adSchemaProviderSpecific; otherwise, it is not used.Res
    --------------------------------------------------------------------------------The OpenSchema method returns self-descriptive information about the data source, such as what tables are in the data source, the columns in the tables, and the data types supported.The QueryType argument is a GUID that indicates the columns (schemas) returned. The OLE DB specification has a full list of schemas.The Criteria argument limits the results of a schema query. Criteria specifies an array of values that must occur in a corresponding subset of columns, called constraint columns, in the resulting Recordset.The constant adSchemaProviderSpecific is used for the QueryType argument if the provider defines its own nonstandard schema queries outside those listed previously. When this constant is used, the SchemaID argument is required to pass the GUID of the schema query to execute. If QueryType is set to adSchemaProviderSpecific but SchemaID is not provided, an error will result.Providers are not required to support all the OLE DB standard schema queries. Specifically, only adSchemaTables, adSchemaColumns, and adSchemaProviderTypes are required by the OLE DB specification. However, the provider is not required to support the Criteria constraints listed earlier for those schema queries. Note  
    Remote Data Service Usage   The OpenSchema method is not available on a client-side Connection object.
      Note  
    In Visual Basic, columns that have a four-byte unsigned integer (DBTYPE UI4) in the Recordset returned from the OpenSchema method on the Connection object cannot be compared to other variables. For more information about OLE DB data types, see Data Types in OLE DB (OLE DB) and Appendix A: Data Types in the Microsoft OLE DB Programmer's Reference.
      Note  
    Visual C/C++ Users   When not using client-side cursors, retrieving the "ORDINAL_POSITION" of a column schema in ADO returns a variant of type VT_R8 in MDAC 2.7, MDAC 2.8, and Windows Data Access Components (Windows DAC) 6.0, while the type used in MDAC 2.6 was VT_I4. Programs written for MDAC 2.6 that only look for a variant returned of type VT_I4 would get a zero for every ordinal if run under MDAC 2.7, MDAC 2.8, and Windows DAC 6.0 without modification. This change was made because the data type that OLE DB returns is DBTYPE_UI4, and in the signed VT_I4 type there is not enough room to contain all possible values without possibly truncation occurring and thereby causing a loss of data.
     
      

  2.   

    The second parameter is an array of query constraints for each QueryType option,but I don't understand it.
      

  3.   

    http://msdn.microsoft.com/en-us/library/ms675274(v=vs.85).aspxadSchemaTables 
     20
     Returns the tables (including views) defined in the catalog that are accessible to a given user.(TABLES Rowset)
     TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
     
      

  4.   

    能举个例子说明?QueryType指明纲要查询类型,Criteria 是个可选参数,且是个数组时的作用?
      

  5.   

    是这样的,不是3个参数么。第二个参数的数组需要几个元素是第一个参数决定的。第一个参数你指定了 adSchemaTables,查表得到,第二个参数需要4个元素
    依次是 TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
    明白了么?
      

  6.   

    如果你查询 adSchemaCatalogs,那么第二个参数只需要1个元素的数组,CATALOG_NAME,你需要传入目录名。
      

  7.   

    明白了一半,续:http://topic.csdn.net/t/20020614/13/803423.html三楼给出的注解不全呀,
    如adSchemaTables   TABLE_CATALOG,这里只有一个表目录,是一个变量不是数组,为何?
      

  8.   

    明白了,谢谢
    补充,OpenSchema返回的是整个表的数据集?还是第一个参数指定返回的数据(也就是它会创建一个新的对象,对象的数据成员的数据是OpenSchema方法返回来的数据)?
      

  9.   

    第二个参数Array(Empty, Empty, strTableName, "Table")是数组?觉得他是函数
      

  10.   

    是函数,这个函数的返回值是一个数组。参考 MSDN。
      

  11.   

    第二个参数array是函数,TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME ,TABLE_TYPE分别是其形参?如第二个参数返回是一个数组,那么是传址?OpenSchema方法返回什么呢?
      

  12.   

    TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME ,TABLE_TYPE分别是其形参这个涉及到一个概念,VB支持一种被叫做可变参数的调用方法,也就是可以接受数量不定的参数。
    Array()就是把它的参数转化为数组。TABLE_CATALOG等是文档的一种描述,和形参无关。OpenSchema方法返回什么呢?
    Returns a Recordset object that contains schema information. The Recordset will be opened as a read-only, static cursor. The QueryType determines what columns appear in the Recordset.
      

  13.   

    Array()的形参类型应该是string?
    能举个例子?比如:用Openschema方法获取数据库表名,表的个数,表是否存在。