J
John
I've run into a problem I can't seem to explain or work around. I'm calling
SqlDataReader.GetSchemaTable() on a database view (SQL Server 2005). It is
returning rows not only for the columns in the view, but also for another
column that is not ouput in the view. For example, I execute the following
code on the Northwind database view named [Alphabetical list of products]:
command.CommandText = "SELECT * FROM [Alphabetical list of products]";
reader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
schemaTable = reader.GetSchemaTable();
This view selects all 10 columns from Products and also CategoryName from
Categories (11 columns total). The tables are joined on CategoryID. When I
run the above code, it returns a schema table that contains 12 rows--all 10
from Products, Categories.CategoryName and also Categories.CategoryID. It
is this last one that is causing problems for me. CategoryID is appearing
twice in my list (once for each table) even though only one of them is in
the SELECT.
So my questions are:
1. Why is Categories.CategoryID getting into the schema table even though it
is not selected?
2. Is there any way to prevent it from getting in there and having the
schema table only show the selected columns?
For those who do not have the Northwind database handy, here's the view's
sql:
SELECT dbo.Products.ProductID, dbo.Products.ProductName,
dbo.Products.SupplierID, dbo.Products.CategoryID,
dbo.Products.QuantityPerUnit, dbo.Products.UnitPrice,
dbo.Products.UnitsInStock, dbo.Products.UnitsOnOrder,
dbo.Products.ReorderLevel, dbo.Products.Discontinued,
dbo.Categories.CategoryName
FROM dbo.Categories
INNER JOIN dbo.Products ON dbo.Categories.CategoryID =
dbo.Products.CategoryID
WHERE (dbo.Products.Discontinued = 0)
Thanks,
John
SqlDataReader.GetSchemaTable() on a database view (SQL Server 2005). It is
returning rows not only for the columns in the view, but also for another
column that is not ouput in the view. For example, I execute the following
code on the Northwind database view named [Alphabetical list of products]:
command.CommandText = "SELECT * FROM [Alphabetical list of products]";
reader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
schemaTable = reader.GetSchemaTable();
This view selects all 10 columns from Products and also CategoryName from
Categories (11 columns total). The tables are joined on CategoryID. When I
run the above code, it returns a schema table that contains 12 rows--all 10
from Products, Categories.CategoryName and also Categories.CategoryID. It
is this last one that is causing problems for me. CategoryID is appearing
twice in my list (once for each table) even though only one of them is in
the SELECT.
So my questions are:
1. Why is Categories.CategoryID getting into the schema table even though it
is not selected?
2. Is there any way to prevent it from getting in there and having the
schema table only show the selected columns?
For those who do not have the Northwind database handy, here's the view's
sql:
SELECT dbo.Products.ProductID, dbo.Products.ProductName,
dbo.Products.SupplierID, dbo.Products.CategoryID,
dbo.Products.QuantityPerUnit, dbo.Products.UnitPrice,
dbo.Products.UnitsInStock, dbo.Products.UnitsOnOrder,
dbo.Products.ReorderLevel, dbo.Products.Discontinued,
dbo.Categories.CategoryName
FROM dbo.Categories
INNER JOIN dbo.Products ON dbo.Categories.CategoryID =
dbo.Products.CategoryID
WHERE (dbo.Products.Discontinued = 0)
Thanks,
John