简体   繁体   中英

How to get table columns values from SQL Server database

var reader = new SqlCommand("Select * from sys.columns", MyCon).ExecuteReader();

This shows this strange output

What I want is to get the columns values (nvarchar, varchar and so on...) from the database table as a string.

This query is not working in SQL Server I tried it

Show Columns From MyTable

it shows

System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword 'From'.'

Start checking this query:

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS

You can access the data that you want to in this view.

Table name, column name, data type... It's all there.

This is the doc from MS, about the information_schema views:

https://docs.microsoft.com/en-us/sql/relational-databases/system-information-schema-views/columns-transact-sql?view=sql-server-ver15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM