I have a Table with GUID date type field as Primery Key. when I run the query in DataSet window of ASP.net, the result is OK, but when I use it in ASP.Net Page it will return an error page like below :
Failed to enable constraints. One or more rows contain values violating non-null,unique, or foreign-key constraints.
The query has not any type of join, and a simple SUM query that add up daily work amounts in a filed based on date range which pass as a parameter to the query and Group by activities that exist in another filed.
This is the table :
And this is the query :CREATE TABLE [dbo].[DailyReport] ( [ReportDate] DATETIME NULL, [ReportId] UNIQUEIDENTIFIER NOT NULL, [ConstructionType] NVARCHAR (50) NULL, [Zone] NVARCHAR (50) NULL, [BuildingName] NVARCHAR (50) NULL, [ActivityId] INT NULL, [TodayWork] REAL NULL, [Decription] NTEXT NULL, PRIMARY KEY CLUSTERED ([ReportId] ASC) );
SELECT SUM(TodayWork) AS SumWork, ActivityId, COUNT(ReportId) AS RecordCount FROM DailyReport WHERE (ConstructionType = N'1') AND (ReportDate >= @DateStart) AND (ReportDate <= @DateFinish) GROUP BY ActivityId