Search code examples
.netvb.netsql-server-2008-r2strongly-typed-dataset

Strongly Typed DataSet Return All Columns When Selecting a Single Column


I am using a Strongly Typed Dataset as DAL.

I want to return a single column from my table for that i wrote the code as

SELECT DISTINCT Floor
FROM            Room
WHERE        (Building = @Building)

But when i previewed the data, it shows me all the columns of the table with Null Value and the column with primary key has -1 value.

This condition raise an Exception when i link this query to a ComboBox ..

cmbFloor.DataSource = da.GetFloorByBuilding(cmbBuilding.Text)
cmbFloor.DisplayMember = "Floor"

Error:

Failed to enable constraints. One or more rows contain values violating non-null,     unique, or foreign-key constraints.

Solution

  • Since each table in Strongly Typed Dataset is stored as a Class. When a query returns a table value or any scalar value. The Dataset returns an class object which contains all properties.