开发者

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 开发者_JAVA技巧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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜