public DataTable GetColumns(string tableName) { DataSet ds = new DataSet(); string sql = "SELECT sys.extended_properties.minor_id,sysobjects.name AS TABLE_NAME, syscolumns.name AS COLUMN_NAME, systypes.name AS DATA_TYPE, syscolumns.length AS CHARACTER_MAXIMUM_LENGTH, CONVERT(nvarchar(200), sys.extended_properties.[value]) AS VALUE FROM sys.extended_properties RIGHT OUTER JOIN sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id INNER JOIN systypes ON syscolumns.xtype = systypes.xtype ON sys.extended_properties.major_id = syscolumns.id AND sys.extended_properties.minor_id = syscolumns.colid WHERE (sysobjects.xtype = 'u' OR sysobjects.xtype = 'v') AND (systypes.name <> 'sysname') AND sysobjects.name=@TABLE_NAME"; using (SqlConnection conn = new SqlConnection(ConnectionString)) { if (conn.State == ConnectionState.Closed) conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add(new SqlParameter("@TABLE_NAME", SqlDbType.NVarChar) { Value = tableName }); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(ds); } return ds != null && ds.Tables.Count > 0 ? ds.Tables[0] : null; }