Cute Bear
Cute Bear

Reputation: 3293

How to call columns allowing null values appropriately

I have a table with following columns

EndDate      DateTime AllowNulls
IsApproved   Bit      AllowNulls

When I send a select query to my table, these two columns generates error.

Lets say this is my select query.

SELECT S.Name, S.Surname,
     CASE 
        WHEN S.EndDate IS NOT NULL AND S.IsApproved = 1 THEN 'Left' 
        WHEN S.EndDate IS NOT NULL AND S.IsApproved = 0 THEN 'Waiting' 
        WHEN S.EndDate IS NULL AND S.IsApproved IS NULL THEN 'Joined' 
        ELSE '' 
      END AS Durumu
FROM STUDENT S

The error I receive: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints

My question is how can I select these null columns appropriately?

P.S. this error has nothing to do with returning same query with same primary key because I have only one entry in my table :)

Upvotes: 0

Views: 146

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460058

I assume you're using a strongly typed DataSet to get your data, am i right?

This error is not raised by your database but by your DataSet.

You can check what caused the exception in this way:

  • Set a breakpoint before you fill the DataTable/DataSet.
  • Execute it in the quick-watch-window of the debugger
  • Execute DataTable.GetErrors to get all rows which RowError is set
  • Look into this property of one or multiple rows to see the actual problem

Maybe you just have to refresh the table via the configuration window, because meanwhile you have changed the constraints in sql-server.

Upvotes: 2

Related Questions