The entity tools used to generate tables help reduce the amount of code and speed up development.
First look
The first figure shows how to connect to the database based on the username and password of the entered connection server address. If an error occurs, the connection fails.
The second figure shows the tables created by all users in the current database.
Then, the system table related to the table information in the database is obtained based on the selected table name. Then, the field type is converted to the C # data type, and the TextBox is output.
Several tables are used here.
Select * from sys. extended_properties table comment and column comment, column arrangement order (without column name)
Select * from sys. columns detailed information field types of all columns in the database table, table fields, names, etc.
Select * from sysobjects where xtype = 'U' -- ID of the table column created by all users
Select * from policypes -- all types of SQL SERVER databases
Select * from syscolumns all field names and lengths
The following uses Ts_Customers as an example to obtain the column name, column type, table comment, and column comment of this table.
Select syscolumns. name, policypes. name as type
, (Select isnull (value, '') from sys. extended_properties ex_p where ex_p.minor_id = 0
And ex_p.major_id = sysobjects. id) as TableDemo
, Ext. value as colName from syscolumns
Inner join sysobjects ON syscolumns. id = sysobjects. id
Inner join policypes ON syscolumns. xtype = policypes. xtype
INNER join sys. extended_properties as ext on ext. major_id = sysobjects. id
And ext. minor_id = syscolumns. colorder
WHERE (sysobjects. name = 'ts _ customer') AND (policypes. name <> 'sysname ')
The effect is as follows:
After the result is obtained, it is written to TextBox cyclically. The code is not pasted here. It is very simple.
Basically achieve the desired effect. unfortunately, I want to dynamically keep the database connection to the app after the test passes. config and then read from the configuration file. the application is being executed. you can only read from the configuration file the next time. so I didn't do this.
Source code download