基于来自不具有直接FK的不同表的数据视图的值来填充网格视图时出错

时间:2012-08-16 20:10:48

标签: asp.net sql gridview dataview

我有这些表格:

TABLE_DIRECTOR
-directorID
-name
-adres
-birthDate
-yearsExperience

TABLE_FILM
-filmID
-directorID
-filmstudioID
-title
-budget
-filmstudioName
-directorName

TABLE_FILMSTUDIO
-filmstudioID
-name
-website
-foundingDate
-numberOfBuildings

我要做的就是用detailsview填充所有filmdirectors。我还有一个gridview,其中包含filmstudio所使用的所有directors个。

要填写此gridview我已将以下代码放入TABLE_FLMSTUDIO_TABLEADAPTER

SELECT TABLE_FILMSTUDIO.filmstudioID, TABLE_FILMSTUDIO.name,
  TABLE_FILMSTUDIO.website, TABLE_FILMSTUDIO.foundingDate,
  TABLE_FILMSTUDIO.numberOfBuildings
FROM TABLE_FILMSTUDIO INNER JOIN
  TABLE_FILM ON TABLE_FILMSTUDIO.filmstudioID = TABLE_FILM.filmstudioID
WHERE (TABLE_FILM.directorID = @directorID)

但是,当我运行页面时,这会给我以下错误

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

有人有想法吗?

1 个答案:

答案 0 :(得分:1)

第一件事:TABLE_FILM -filmID -directorID -title -budget -filmstudioName -directorName不包含 filmstudioID但你在INNER JOIN中使用它作为TABLE_FILM.filmstudioID。

其次,错误表明您的某个表包含重复数据。 (违反外键)