From sql I need to get columns, tables and views names.
With this solution I am able to get only base table names and columns but not the view names.
SqlDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo);
DataTable schemaTable = reader.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
var baseTableName = row["BaseTableName"].ToString(),
var columnName = row["ColumnName"].ToString(),
var baseColumnName = row["BaseColumnName"].ToString()
}
For example:
My view:
CREATE VIEW view1 as
select * from table1 inner join table2 on table1.id1 = table.id2
sql = "select col1, col2 from view1"
then I get:
BaseTableName: table1
BaseColumnName:col1
ColumnName:col1
BaseTableName: table2
BaseColumnName:col2
ColumnName:col2
I can't get view name from sql. So instead of table1 and table2 I would like to get view1. I tried with all different CommandBehavior options. Any ideas?
I use .NET Framework 4.7.2