I have a database (in SQL Server 2008 SP3) and I need all the schema names, table names and column names in the related hierarchy in C # code, I have the SQLElement class as follows:
public class SQLElement { public string SchemaName { get; set; } public string TableName { get; set; } public string ColumnName { get; set; } }
And there is a list like:
List<SQLElement> SQLElementCollection = new List<SQLElement>();
So, how can I read Names from the database and add them to this list (SQLElementCollection)?
for example, suppose we create a table as follows:
Create Table [General].[City] ( [Id] BIGINT NOT NULL IDENTITY(1, 1), [Title] NVARCHAR(30) NOT NULL DEFAULT (N''), [Province_Id] BIGINT NOT NULL )
and I need a list like:
[0]={SchemaName="General", TableName="City", ColumnName="Id"} [1]={SchemaName="General", TableName="City", ColumnName="Title"} [2]={SchemaName="General", TableName="City", ColumnName="Province_Id"}
Does anyone have any ideas about this?
Edit:
In the next step, can we get the type of each column or the properties associated with it?
c # sql sql-server tsql
Saeid
source share