Recently working with SQL statements query the name of all the fields in the table, online query, found that different database query methods are different, for example:
SQL Server
All field names for the query table:
Select name from syscolumns Where id=object_id (' table name ')
Sqlite
Query all field names in the table;
SELECT name from sqlite_master WHERE type= 'table ' ORDER by name;
Oracle
View all fields
Select column_name from User_tab_columns where table_name= ' Zw_yingyez '
Considering the generality of SQL statements, combined with the abstract factory model, individuals combine DataTable, DataSet, and basic SQL statements to design a common approach:
list<string> filedlist = new list<string> ();
DataSet ds = _autotestsql.readmethod (String. Format ("select * FROM {0} ORDER BY [autoid]", table name));
DataTable dt = new DataTable ();
Dt. Clear ();
DT = ds. Tables[0];
for (int j = 0; j < dt. Columns.count; J + +)
{
Filedlist.add (dt. COLUMNS[J]. Columnname.trim ());
}
Return filedlist;//field list for all tables
In this way, all the fields are indirectly obtained;
Names of all fields in the SQL query table