本文介绍了如何解决“无法启用约束”的问题。一行或多行包含违反非空,唯一或外键约束的值。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我调用该函数时
when i call the function
public DataTable GetAllBySurSurveyId(Int64 surSurveyId) { DataTable dtSurSurveyTeam = null; try { dtSurSurveyTeam = Adapter.sp_4_15_GetAllBySurSurveyId(surSurveyId); } catch (Exception ex) { ErrorWriter.WriteError(ex, "FunctionName --> GetDataTable", RequestPage); } return dtSurSurveyTeam; }上述错误来了。我用storeprocedure绑定了quary,storeprocedure显示了数据。 storeprocedure:
the above error came. i have binded the quary with storeprocedure and the storeprocedure is showing the data. storeprocedure :
ALTER PROCEDURE [dbo].[sp_4_15_GetAllBySurSurveyId] -- Add the parameters for the stored procedure here @surSurveyId AS nvarchar(MAX) AS BEGIN DECLARE @Sql1 AS NVARCHAR(MAX) SET @Sql1 = 'SELECT T.SurSurveyTeamId, O.OfficeName, T.SurveyTeamName, T.TeamDescription, (SELECT COUNT(SurSurveyTeamMemberId) AS TotalMembers FROM SurRelationSurveyTeamToTeamMember AS RTM WHERE (SurSurveyTeamId = R.SurSurveyTeamId)) AS TotalMembers FROM SurRelationSurveyToSurveyTeam AS R LEFT OUTER JOIN SurSurveyTeam AS T ON T.SurSurveyTeamId = R.SurSurveyTeamId LEFT OUTER JOIN UsmOffice AS O ON O.UsmOfficeId = T.UsmOfficeId WHERE (R.SurSurveyId = '+@surSurveyId+')' EXECUTE (@Sql1) END推荐答案
正如错误信息所示,约束类型您可能违反的是非null,唯一或外键约束。除非您自己添加它们,否则它们只能在DataTable和DataSet架构由数据源等自动生成时创建。 此问题通常由 - >未设置为AllowDBNull的列返回空值 - >使用相同的主键返回重复的行。 - >数据库与数据集之间的列定义(例如字段大小)不匹配 As the error message says, the types of constraints that you might violate are non-null, unique, or foreign-key constraints. Unless you add them yourself, they can only be created when DataTable and DataSet schema is generated automatically, by the Data Source or the like. This problem is usually caused by -> null values being returned for columns not set to AllowDBNull -> duplicate rows being returned with the same primary key. -> a mismatch in column definition (e.g. size of char fields) between the database and the dataset
更多推荐
如何解决“无法启用约束”的问题。一行或多行包含违反非空,唯一或外键约束的值。错误
发布评论