2, get the database schema information, here I take the database table list for example, the code is as follows
<summary>///gets a tabular list of databases that can be used for all OLE DB connected databases///</summary>///<param name= "sConnStr" > Database connection characters String </param>///<returns> table list array </returns> public string[] Gettablist (string sconnstr) {if (sconnst r = = null) throw new ArgumentNullException ("sConnStr");
String[] stblist; using (OleDbConnection conn = new OleDbConnection (sConnStr)) {Conn. Open (); DataTable DT = conn. GetOleDbSchemaTable (OleDbSchemaGuid.Tables, new object[] {null, NULL, NULL, "TABLE"}); Conn. Close ();
if (dt. Rows.Count > 0) {stblist = new String[dt. Rows.Count]; int i = 0; foreach (DataRow dr in Dt. Rows) {Stblist[i] = dr["table_name"]. ToString (); i + 1; } else {stblist = new string[1]; Stblist[0] = "< no form >"; } return stblist; }
This is the key to using the OleDbConnection object's GetOleDbSchemaTable method to demonstrate schema information
GetOleDbSchemaTable returns a DataTable populated with schema information.
You can make this DataTable appear directly, which is the detailed information.
If you need to look up other information about the database schema,
such as the data source, table and view of the directory and the constraints exist. Schema information in a table includes primary keys, columns, and AutoNumber fields.
Only need to change the GetOleDbSchemaTable parameter settings, the specific parameters can be viewed
3, call Gettablist (SCONNSTR) will be able to return to that database in the table list
sConnStr is connected to that kind of database and can return results as long as it is supported by Ado.net.
When the connection is a UDL file, want to connect to the other database through the UDL file, the selected driver must also be OLE DB.
Reference:
OleDbSchemaGuid member http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ Frlrfsystemdataoledboledbschemaguidmemberstopic.asp
How to: Retrieve schema information using getoledbschematable and Visual C #. NET
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.