During database operations, we often need to read the architecture information from the database. I used to use SQL statements. This is convenient for incomplete information. Many of them need to guess by themselves or use sqlserver's event tracker to track and see how sqlserver Manager works.
In. net. The dbconnection object has a getschema method, which is very powerful and can obtain a lot of database architecture information, which is generally enough for us. However, simply use it to return the table name, as shown below:
String [] restrictions = new string [4];
Restrictions [3] = "base table"
Datatable table = connection. getschema ("tables", restrictions );
As shown in the above Code, all the user table schema information in the database can be filled in the datatable.
The following information is returned for tables:
For other architecture information, see the description in msdn.
The most convenient way to obtain schema information for each table is to use dataadapter. fillschema. The example is as follows:
Sqlcommand cmd = connection. createcommand ();
Cmd. commandtext = "select * from" + tblsection. tablename + "where 0 = 1"
Sqldataadapter da = new sqldataadapter (CMD );
Datatable tbltable = new datatable ();
Da. fillschema (tbltable, schematype. source );
In this way, you can easily read the complete architecture information of the table from the tbltable.
Appendix: there are various methods to obtain the database architecture, and the research is dizzy. Under. net, this is the simplest method I have found.