请问OpenSchema方法的详细用法?(200分)

  • 主题发起人 慕容乾坤
  • 开始时间

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟我正在用ASP实现从数据库中提取表名和字段名,可是[red]OpenSchema[/red]
的用法不是很明了,有哪位大侠可以告诉我?最好在有个例子。
 
L

lyywy

Unregistered / Unconfirmed
GUEST, unregistred user!

Platform SDK: Host Integration Server
OpenSchema Method
The OpenSchema method on a Connection object obtains database schema information from the provider.

recordset = connection.OpenSchema ( QueryType, Criteria, SchemaID )

Parameters
QueryType
This parameter specifies a SchemaEnum value that indicates the type of schema query to run.
The SchemaEnum values supported by the OLE DB Provider for AS/400 and VSAM can be one of the following constants: Enumeration Value Description
adSchemaColumns 4 This value indicates that the QueryType is requesting column information for tables on the server (not supported when connecting to mainframes ).
adSchemaIndexes 12 This value indicates that the QueryType is requesting index information about the tables on the server (not supported when connecting to mainframes ).
adSchemaTables 20 This value indicates that the QueryType is requesting information about the tables on the server.
adSchemaProviderTypes 22 This value indicates that the QueryType is requesting provider-type information.



The SchemaEnum values supported by the OLE DB Provider for DB2 and the ODBC Driver for DB2 can be one of the following constants: Enumeration Value Description
adSchemaColumns 4 This value indicates that the QueryType is requesting column information for tables on the server (not supported when connecting to mainframes ).
adSchemaIndexes 12 This value indicates that the QueryType is requesting index information about the tables on the server (not supported when connecting to mainframes).
adSchemaProcedures 16 This value indicates that the QueryType is requesting information about stored procedures on the server.
adSchemaTables 20 This value indicates that the QueryType is requesting information about the tables on the server.
adSchemaProviderTypes 22 This value indicates that the QueryType is requesting provider-type information.
adSchemaProcedureParameters 26 This value indicates that the QueryType is requesting information about parameters used by stored procedures on the server.
adSchemaPrimaryKeys 28 This value indicates that the QueryType is requesting information about the primary keys for tables on the server.



Criteria
This optional parameter specifies an array of query constraints for each QueryType option, as listed below.
The values supported by the OLE DB Provider for AS/400 and VSAM can be one of the following constants depending on the QueryType: QueryType / Enumeration
adSchemaColumns
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
adSchemaIndexes
TABLE_CATALOG
TABLE_SCHEMA
INDEX_NAME
TYPE
TABLE_NAME
adSchemaTables
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
TABLE_TYPE
adSchemaProviderTypes
DATA_TYPE
BEST_MATCH



The values supported by the OLE DB Provider for DB2 and the ODBC Driver for DB2 can be one of the following constants depending on the QueryType: QueryType / Enumeration
adSchemaColumns
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
adSchemaIndexes
TABLE_CATALOG
TABLE_SCHEMA
INDEX_NAME
TABLE_NAME
adSchemaPrimaryKeys
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
adSchemaProcedures
PROCEDURE_CATALOG
PROCEDURE_SCHEMA (see Notes)
PROCEDURE_NAME
PROCEDURE_TYPE
adSchemaProcedureParameters
PROCEDURE_CATALOG
PROCEDURE_SCHEMA (see Notes)
PROCEDURE_NAME
PROCEDURE_TYPE
adSchemaProviderTypes
DATA_TYPE
BEST_MATCH
adSchemaTables
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
TABLE_TYPE



Note The adSchemaindexes TYPE restriction is not supported by the OLE DB Provider for DB2.

The adSchemaProcedures PROCEDURE_SCHEMA, and adSchemaProcedureParameters PROCEDURE_SCHEMA restrictions are not supported when connecting to DB/2 on OS/390 platforms.

SchemaID
This optional parameter specifies the GUID for a provider-schema schema query not defined by the OLE DB specification. This parameter is required if the QueryType parameter is set to adSchemaProviderSpecific
otherwise, it is not used. This parameter is not supported by the OLE DB Provider for AS/400 and VSAM.
Return Values
Returns a Recordset object that contains schema information requested.

Remarks
The OpenSchema method on a Connection object is used to return information about the data source, such as information about the tables on the server and the columns in the tables.

The Criteria argument is an array of values that can be used to limit the results of a schema query. Each schema query supports a different set of parameters. The actual schemas are defined by the OLE DB specification under the IDBSchemaRowset interface. The schema queries supported in ADO 1.5 and later by the OLE DB Provider for AS/400 and VSAM are listed above.

The OpenSchema method allows an application to pass at run time the target library of a Partioned Data Set (PDS/PDSE), a dataset, or a member name as one of the Criteria array arguments to retrieve the schema.

Providers are not required to support all of the OLE DB standard schema QueryType values. 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 above for those schema queries. Support for other schema QueryType values is optional.

The schema information specified in OLE DB is based on the assumption that providers support the concepts of a catalog and a schema. The ANSI SQL 92 specification defines them as follows:

A catalog contains one or more schemas, but always contains a schema named INFORMATION_SCHEMA which contains the views and domains of the information schema. In Microsoft&reg
SQL Server and Microsoft&reg
Access terms, a catalog is a database
in ODBC 2.x terms, a catalog is a qualifier.
A schema is a collection of database objects that are owned or have been created by a particular user. In Microsoft SQL Server and ODBC 2.x terms, a schema is an owner
there is no equivalent to a schema in a Microsoft Access database.
Schema information in ADO and OLE DB is retrieved using predefined schema rowsets. The following section lists the contents of each schema rowset supported by the OLE DB Provider for AS/400 and VSAM or the OLE DB Provider for DB2.

Built on Monday, August 14, 2000
 
L

lyywy

Unregistered / Unconfirmed
GUEST, unregistred user!
See Also
Visual Basic Example | Visual C++ Example | Visual J++ Example

Open Method (ADO Connection) | Open Method (ADO Record) | Open Method (ADO Recordset) | Open Method (ADO Stream) | Appendix A: Providers

Applies To: Connection Object
ADO API Reference
OpenSchema Method
Obtains database schema information from the provider.

Syntax
Set recordset = connection.OpenSchema (QueryType, Criteria, SchemaID)
Return Values
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.
Remarks
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 above. 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 of 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 above for those schema queries.

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 Chapter 13 and Appendix A of the Microsoft OLE DB Programmer's Reference.

See Also
Visual Basic Example | Visual C++ Example | Visual J++ Example

Open Method (ADO Connection) | Open Method (ADO Record) | Open Method (ADO Recordset) | Open Method (ADO Stream) | Appendix A: Providers

Applies To: Connection Object
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
太好了,我找了半天也没找到具体参数的资料,谢谢。
再看看有没有举例子的,随后就加分。
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(]
有个重大问题,我调出了所有的系统表和视图,就是没有用户自己建的表和视图
请问大侠们怎样在OpenSchema中加限制条件使之可以得到需要的数据集呀?
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
lyywy请赶快出手
 
L

lyywy

Unregistered / Unconfirmed
GUEST, unregistred user!
See Also
OpenSchema Method
ADO Samples
OpenSchema Method Example (VJ++)
This example uses the OpenSchema method to display the name and type of each table in the Pubs database.

// BeginOpenSchemaJ
import com.ms.wfc.data.*;
import java.io.*;
import com.ms.com.*;

public class OpenSchemaX
{
// The main entry point of the application.

public static void main (String[] args)
{
OpenSchemaX();
OpenSchemaX2();
System.exit(0);
}

// OpenSchemaX Function
static void OpenSchemaX()
{
// Define ADO Objects
Connection cnn1 = null;
Recordset rstSchema = null;

// Declarations
String strCnn;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int intDisplayRecords = 5;
int intRecordCount = 0;

try
{

cnn1 = new Connection();
strCnn = "Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C://Program Files//Microsoft " +
"Office//Office//Samples//Northwind.mdb;" +
"User Id=admin;Password=;";
cnn1.open(strCnn);
rstSchema = cnn1.openSchema(AdoEnums.Schema.TABLES);

while (!rstSchema.getEOF())
{

System.out.println("Table Name: " +
rstSchema.getField("TABLE_NAME").getString()+"/n"+
"Table Type: " +
rstSchema.getField("TABLE_TYPE").getString()+"/n");
intRecordCount++;
if ( intRecordCount == intDisplayRecords)
{
System.out.println("Press <Enter> to continue..");
in.readLine();
intRecordCount = 0;
}
rstSchema.moveNext();

}
System.out.println("Press <Enter> to continue..");
in.readLine();
// Cleanup objects before exit
rstSchema.close();
cnn1.close();

}
catch(AdoException ae)
{
// Notify user of any errors that result from ADO.

// As passing a Recordset, check for null pointer first.
if(rstSchema != null)
{
PrintProviderError(rstSchema.getActiveConnection());
}
else
{
System.out.println("Exception: " + ae.getMessage());
}
}
// System read requires this catch.
catch(java.io.IOException je)
{
PrintIOError(je);
}
}

// OpenSchemaX2 Function

static void OpenSchemaX2()
{
// Define ADO Objects
Connection cnn2 = null;
Recordset rstSchema = null;

// Declarations
String strCnn;
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
int intDisplayRecords = 5;
int intRecordCount = 0;

try
{
cnn2 = new Connection();
strCnn = "Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C://Program Files//Microsoft " +
"Office//Office//Samples//Northwind.mdb;" +
"User Id=admin;Password=;";
cnn2.open(strCnn);

Variant[] va = new Variant[4];
va[0] = new Variant();
va[1] = new Variant();
va[2] = new Variant();
va[3] = new Variant("VIEW");
rstSchema = cnn2.openSchema(AdoEnums.Schema.TABLES,(Object[])va);

while (!rstSchema.getEOF())
{
System.out.println("Table Name: " +
rstSchema.getField("TABLE_NAME").getString()+"/n"+
"Table Type: " +
rstSchema.getField("TABLE_TYPE").getString()+"/n");
intRecordCount++;
if ( intRecordCount == intDisplayRecords)
{
System.out.println("Press <Enter> to continue..");
in.readLine();
intRecordCount = 0;
}
rstSchema.moveNext();

}
System.out.println("Press <Enter> to continue..");
in.readLine();
// Cleanup Objects before exit.
rstSchema.close();
cnn2.close();

}
catch(AdoException ae)
{
// Notify user of any errors that result from ADO.

// As passing a Recordset, check for null pointer first.
if(rstSchema != null)
{
PrintProviderError(rstSchema.getActiveConnection());
}
else
{
System.out.println("Exception: " + ae.getMessage());
}
}
// System read requires this catch.
catch(java.io.IOException je)
{
PrintIOError(je);
}

}
// PrintProviderError Function

static void PrintProviderError( Connection Cnn1 )
{
// Print Provider errors from Connection object.
// ErrItem is an item object in the Connection’s Errors collection.
com.ms.wfc.data.Error ErrItem = null;
long nCount = 0;
int i = 0;

nCount = Cnn1.getErrors().getCount();

// If there are any errors in the collection, print them.
if( nCount > 0);
{
// Collection ranges from 0 to nCount - 1
for (i = 0
i< nCount
i++)
{
ErrItem = Cnn1.getErrors().getItem(i);
System.out.println("/t Error number: " + ErrItem.getNumber()
+ "/t" + ErrItem.getDescription() );
}
}

}

// PrintIOError Function

static void PrintIOError( java.io.IOException je)
{
System.out.println("Error /n");
System.out.println("/tSource = " + je.getClass() + "/n");
System.out.println("/tDescription = " + je.getMessage() + "/n");
}
}
// EndOpenSchemaJ

See Also
OpenSchema Method
 
L

lyywy

Unregistered / Unconfirmed
GUEST, unregistred user!
See Also
OpenSchema Method
ADO Samples
OpenSchema Method Example (VC++)
This example uses the OpenSchema method to display the name and type of each table in the Pubs database.

// BeginOpenSchemaCpp
#import "c:/Program Files/Common Files/System/ADO/msado15.dll" /
no_namespace rename("EOF", "EndOfFile")

#include <ole2.h>
#include <stdio.h>
#include <oleauto.h>
#include <conio.h>

// Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void OpenSchemaX(void);
void OpenSchemaX2(void);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &amp;e);

///////////////////////////////////////////////////////////
// //
// Main Function //
// //
///////////////////////////////////////////////////////////

void main()
{
if(FAILED:):CoInitialize(NULL)))
return;

OpenSchemaX();

printf("Press any key to see the results of 2nd "
"function.../n/n");
getch();

OpenSchemaX2();

::CoUninitialize();
}

///////////////////////////////////////////////////////////
// //
// OpenSchemaX Function //
// //
///////////////////////////////////////////////////////////

void OpenSchemaX()
{
// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstSchema = NULL;

//Other Variables
HRESULT hr = S_OK;

_bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
"Initial Catalog=pubs;User Id=sa;Password=;");

try
{
// Open connection.
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
pConnection->Open (strCnn, "", "", adConnectUnspecified);

pRstSchema = pConnection->OpenSchema(adSchemaTables);

while(!(pRstSchema->EndOfFile))
{
_bstr_t table_name = pRstSchema->Fields->
GetItem("TABLE_NAME")->Value;

printf("Table Name: %s/n",(LPCSTR) table_name);

_bstr_t table_type = pRstSchema->Fields->
GetItem("TABLE_TYPE")->Value;

printf("Table type: %s/n/n",(LPCSTR) table_type);

pRstSchema->MoveNext();

int intLine = intLine + 1;
if (intLine % 5 == 0)
{
printf("/nPress any key to continue...");
getch();
//Clear the screen for the next display
system("cls")

}
}
// Clean up objects before exit.
pRstSchema->Close();
pConnection->Close();
}

catch (_com_error &amp;e)
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError(pConnection);
PrintComError(e);
}
}

///////////////////////////////////////////////////////////
// //
// OpenSchemaX2 Function //
// //
///////////////////////////////////////////////////////////
void OpenSchemaX2()
{
HRESULT hr = S_OK;
// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_ConnectionPtr pConnection2 = NULL;
_RecordsetPtr pRstSchema = NULL;

_bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
"Initial Catalog=pubs;User Id=sa;Password=;");

try
{
// Open connection.
TESTHR(pConnection2.CreateInstance(__uuidof(Connection)));
pConnection2->Open (strCnn, "", "", adConnectUnspecified);

// Create a safearray which takes four elements,and pass it as
// 2nd parameter in OpenSchema method.
SAFEARRAY FAR* psa = NULL;
SAFEARRAYBOUND rgsabound;
_variant_t var;
_variant_t Array;
rgsabound.lLbound = 0;
rgsabound.cElements = 4;
psa = SafeArrayCreate(VT_VARIANT, 1, &amp;rgsabound);
var.vt = VT_EMPTY;

long ix;
ix = 0;
SafeArrayPutElement(psa, &amp;ix, &amp;var);

ix= 1;
SafeArrayPutElement(psa, &amp;ix, &amp;var);

ix = 2;
SafeArrayPutElement(psa, &amp;ix, &amp;var);

var.vt = VT_BSTR;
char * s1 = "VIEW";
_bstr_t str = s1;
var.bstrVal = str;

ix = 3;
SafeArrayPutElement(psa, &amp;ix, &amp;var);

Array.vt = VT_ARRAY|VT_VARIANT;
Array.parray = psa


pRstSchema = pConnection2->OpenSchema(adSchemaTables,&amp;Array);

while(!(pRstSchema->EndOfFile))
{
printf("Table Name: %s/n", (LPCSTR) (_bstr_t) pRstSchema->
Fields->GetItem("TABLE_NAME")->Value);

printf("Table type: %s/n/n",(LPCSTR) (_bstr_t) pRstSchema->
Fields->GetItem("TABLE_TYPE")->Value);

pRstSchema->MoveNext();

int intLine = intLine + 1;
if (intLine % 5 == 0)
{
printf("/nPress any key to continue...");
getch();
//Clear the screen for the next display
system("cls")

}
}
// Clean up objects before exit.
pRstSchema->Close();
pConnection2->Close()

} // End Try statement.

catch (_com_error &amp;e)
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError(pConnection2);
PrintComError(e);
}
}

///////////////////////////////////////////////////////////
// //
// PrintProviderError Function //
// //
///////////////////////////////////////////////////////////

void PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;

if( (pConnection->Errors->Count) > 0)
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(long i = 0;i < nCount;i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("/t Error number: %x/t%s", pErr->Number,
pErr->Description);
}
}
}

///////////////////////////////////////////////////////////
// //
// PrintComError Function //
// //
///////////////////////////////////////////////////////////

void PrintComError(_com_error &amp;e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());

// Print COM errors.
printf("Error/n");
printf("/tCode = %08lx/n", e.Error());
printf("/tCode meaning = %s/n", e.ErrorMessage());
printf("/tSource = %s/n", (LPCSTR) bstrSource);
printf("/tDescription = %s/n", (LPCSTR) bstrDescription);
}
// EndOpenSchemaCpp

See Also
OpenSchema Method
 
L

lyywy

Unregistered / Unconfirmed
GUEST, unregistred user!
以上是vj++,vc++的例子。
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
to lyywy:
vj++那两个例子用的openschema和ASP有点不一样
vc++那两个例子就是普通的例子,第一个和第二个基本一样,都是调用所有表和视图
我想要的是调出普通用户建的表的例子
我已经可以根据参数TABLE_TYPE分别调出系统表,视图
但是用户应用的表就是调不出来
请继续帮忙好吗。[:)]
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
我终于知道了参数的用法,哎,每个参数要一点一点的试呀。
不能藏私,写出来供大家查阅
Set recordset = connection.OpenSchema (QueryType, Criteria, SchemaID)
函数有三个参数,SCHEMAID用到的不多,不介绍了
参数

QueryType 所要运行的模式查询类型,可以为下列任意常量。

Criteria 可选。每个 QueryType 选项的查询限制条件数组,如下所列:

QueryType 值 Criteria 值
AdSchemaAsserts CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
AdSchemaCatalogs CATALOG_NAME
AdSchemaCharacterSets
CHARACTER_SET_CATALOG
CHARACTER_SET_SCHEMA
CHARACTER_SET_NAME
AdSchemaCheckConstraints CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
AdSchemaCollations COLLATION_CATALOG
COLLATION_SCHEMA
COLLATION_NAME
AdSchemaColumnDomainUsage DOMAIN_CATALOG
DOMAIN_SCHEMA
DOMAIN_NAME
COLUMN_NAME
AdSchemaColumnPrivileges TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
GRANTOR
GRANTEE
adSchemaColumns TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
adSchemaConstraintColumnUsage TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
adSchemaConstraintTableUsage TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
adSchemaForeignKeys PK_TABLE_CATALOG
PK_TABLE_SCHEMA
PK_TABLE_NAME
FK_TABLE_CATALOG
FK_TABLE_SCHEMA
FK_TABLE_NAME
adSchemaIndexes TABLE_CATALOG
TABLE_SCHEMA
INDEX_NAME
TYPE
TABLE_NAME
adSchemaKeyColumnUsage CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
adSchemaPrimaryKeys PK_TABLE_CATALOG
PK_TABLE_SCHEMA
PK_TABLE_NAME
adSchemaProcedureColumns PROCEDURE_CATALOG
PROCEDURE_SCHEMA
PROCEDURE_NAME
COLUMN_NAME
adSchemaProcedureParameters PROCEDURE_CATALOG
PROCEDURE_SCHEMA
PROCEDURE_NAME
PARAMTER_NAME
adSchemaProcedures PROCEDURE_CATALOG
PROCEDURE_SCHEMA
PROCEDURE_NAME
PROCEDURE_TYPE
adSchemaProviderSpecific 参见说明
adSchemaProviderTypes DATA_TYPE
BEST_MATCH
adSchemaReferentialConstraints CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
adSchemaSchemata CATALOG_NAME
SCHEMA_NAME
SCHEMA_OWNER
adSchemaSQLLanguages <无>
adSchemaStatistics TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
adSchemaTableConstraints CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
CONSTRAINT_TYPE
adSchemaTablePrivileges TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
GRANTOR
GRANTEE
adSchemaTables TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
TABLE_TYPE
adSchemaTranslations TRANSLATION_CATALOG
TRANSLATION_SCHEMA
TRANSLATION_NAME
adSchemaUsagePrivileges OBJECT_CATALOG
OBJECT_SCHEMA
OBJECT_NAME
OBJECT_TYPE
GRANTOR
GRANTEE
adSchemaViewColumnUsage VIEW_CATALOG
VIEW_SCHEMA
VIEW_NAME
adSchemaViewTableUsage VIEW_CATALOG
VIEW_SCHEMA
VIEW_NAME
adSchemaViews TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME

看了这么多眼晕吧[:)],其实通常就用两种参数
一个是[red]adSchemaTables[/red],另一个是[red]adSchemaColumns[/red]
看名字就知道一个是提取表名和视图名及其信息,另一个是提取字段名及其信息
adSchemaTables对应4个参数,列表里有
今天太晚了,回家我爸可能打我[:)],所以明天上班我在给大家写出来。
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
好,接着写.
介绍了参数后,我给大家举个小例子,提取数据库中的表名。ASP的
<html>

<head>
<meta http-equiv="Content-Type" content="text/html
charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>

<body>
<%connstr ="dbq=sa;server=(local);datebase=logrefer;driver={sql server};uid=sa;pass="
Set sim = Server.CreateObject("ADODB.Connection")
sim.Open connstr
Set rstSchema = sim.OpenSchema(20)
Do Until rstSchema.EOF
response.write "Table name: " &amp
rstSchema("TABLE_NAME") &amp
"----"&amp
"Table type: " &amp
rstSchema("TABLE_TYPE") &amp
"<br>"
rstSchema.MoveNext
Loop
%>
</body>

</html>
lyywy的帖子说明了20对应着[red]adSchemaTables[/red]
这个例子是很普通的,[red]adSchemaTables[/red]后面没有任何的限制
如果[green]OpenSchema[/green]这么写的话,大家就明白了每个参数的作用

[brown]Set rstSchema = sim.OpenSchema(20,Array("pubs",Empty,Empty,"TABLE"))[/brown]

每个逗号前面的对应一个Criteria 值,这个例子说明从PUBS数据库中提取TABLE类型的表。也就是用户建的表.
你还可以在倒数第二个参数中输入表名,可以提取唯一的表。可是第二个参数[red]TABLE_SCHEMA[/red]
我还不知道他是什么意思。[:(]
adSchemaColumns的用法,基本一样,大家自己试验一下就行了。

 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 

慕容乾坤

Unregistered / Unconfirmed
GUEST, unregistred user!
本题结束了,只有lyywy一个人回答了问题,所以[h4]200[/h4]的[red]大奖[/red]就由lyywy一人领走了。
 
顶部