ado| Schema | data | Database use Ado.net to get database schema information
Autumn Maple 2004-7-3
At the time of development, it is sometimes necessary to obtain database schema information to get some other information about the database, such as stored procedures, views, tables, types of fields, notes and so on. This can be achieved by oledb.net the data provider more succinctly.
GetOleDbSchemaTable Method of OleDbConnection
This object in the Ado.net object model acts as a connection to the data source, connects the database through the connection object, or disconnects from the database to free valuable resources. What we need to use here is the GetOleDbSchemaTable method of the OleDbConnection object,
The definition is as follows:
Public DataTable GetOleDbSchemaTable (Guid schema,object[] restrictions);
method returns a DataTable object;
The first parameter is a OleDbSchemaGuid enumeration value that specifies the type of schema information that can be used to determine the type of schema required, such as tables, columns, views, and so on, to refer to MSDN;
The second parameter, restrictions, is a oject array data type that acts as a filter, and if the second argument is set to NULL, it returns all the information for the specified OleDbSchemaGuid enumeration.
The following is illustrated with the sample program, the sample interface is as follows:
The entire form includes:
A textbox that is used to enter the database connection string;
A DataGrid, used to display schema information;
View the button and click Get schema information.
Here, for example, SQL Server's Northwind database is handled as follows in the View button events:
Pass the connection string into the Getsqldbschemausingoledbconnection function through the text box, connect the database by the OleDbConnection object, and obtain the schema information.
This method returns the schema information for the Customers table, and of course, if you connect to an Access database, the above function can be executed correctly only by modifying the connection string and the query string.
Third, other supplementary
What we are talking about here is the acquisition of database schema information through oledb.net. Other means can be implemented for specific data providers such as SQL Client.net and Oracle Client.net.
Like what:
You can get data from the information Schema view in SQL Server:
SELECT * from INFORMATION_SCHEMA. TABLES
Get a list of table names:
SELECT table_name from INFORMATION_SCHEMA. TABLES WHERE table_type = ' BASE TABLE '
To get a list of view names:
SELECT table_name from INFORMATION_SCHEMA. TABLES WHERE table_type = ' VIEW '
You can also view the online Help for SQL SERVER by getting columns, stored procedures, and so on.
Oracle databases allow you to query Oracle data dictionaries for this information, and refer to Oracle's related documentation.
This article refers to: "MSDN", "Ado.net Core Reference", "SQL Server 2000 Books Online"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.