1

I build asp.net application, for db i use TableAdapter. Select Query

SELECT
    U.empID,
    U.firstName,
    U.lastName,
    R.name AS Role
FROM
    USER_T AS U
INNER JOIN USER_ROLES_T AS UR ON U.empID = UR.empID
INNER JOIN ROLES_T AS R ON UR.roleID = R.typeID

empId with constraint primary key. Employee has many role attributes, it named role.

When I perform request for user data from db:

UsersTableAdapter usersTableAdapter = new UsersTableAdapter();
DataBase.UsersDataTable users = usersTableAdapter.GetUsers();

I get following exception:

Controllers.UI.Login.LoginController|System.Data.ConstraintException: Failed to

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

If I perform request select-request with any admin program it get

    28 Roman Ivanov Admin
    28 Roman Ivanov Developer

I understand, this happens because of primary key empId, how can this problem get solved? How can i remove a primary key from adapter?

flybox
  • 224
  • 3
  • 12
  • Possible duplicate of [Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints](http://stackoverflow.com/questions/7026566/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null) – Gilad Green Jul 27 '16 at 06:53
  • as a sum of, what would be the result you want? – Vijunav Vastivch Jul 27 '16 at 06:57

1 Answers1

2

enter image description here

open UsersTableAdapter design in visual studio like above image and right click on it and delete key then save , it will work perfectly.

Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40