Stanley
Stanley

Reputation: 13

Programmatically accessing structure of tables in the database

How can I programatically access (just access) the structure of the tables in my database. If I have a table Employee with attributes Id, Name, SSN etc. then I want to access Id, Name and SSN in code behind files of my Web Forms. I know LINQ and Entity Framework will be involved but I cannot figure out how to do this. I am using ASP.NET 4.

I dont want rows stored in the tables. I just want to know what is the structure of the table i.e. what are the columns. I want to add more columns in the tables in the future.

Thanks.

Upvotes: 1

Views: 176

Answers (1)

Davide Piras
Davide Piras

Reputation: 44605

I would not use entity framework then, I would use normal ADO.NET to load a DataTable with a kind of SELECT TOP 1 * FROM dbo.TableName WITH (NOLOCK) ( if you are in SQL Server scenario ), then the table contains the columns, looping on the table columns you see their type and name and that's the table schema/structure you are looking for.

You can also manipulate the tables and add columns; not in this exact way I discussed above, but it's possible.

Upvotes: 1

Related Questions