违反了 PRIMARY KEY 约束 'PK_TBL_Profiles'。不能在对象 'dbo.TBL_Profiles' 中插入重复键。
异常详细信息:System.Data.SqlClient.SqlException:违反了PRIMARYKEY约束'PK_TBL_Profiles'。不能在对象'dbo....
异常详细信息: System.Data.SqlClient.SqlException: 违反了 PRIMARY KEY 约束 'PK_TBL_Profiles'。不能在对象 'dbo.TBL_Profiles' 中插入重复键。
语句已终止。
源错误:
行 94: {
行 95: PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
行 96: object val = cmd.ExecuteScalar();////出错
行 97: cmd.Parameters.Clear();
行 98: return val;
堆栈跟踪:
[SqlException (0x80131904): 违反了 PRIMARY KEY 约束 'PK_TBL_Profiles'。不能在对象 'dbo.TBL_Profiles' 中插入重复键。
语句已终止。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +52
System.Data.SqlClient.SqlDataReader.get_MetaData() +130
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +371
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +45
System.Data.SqlClient.SqlCommand.ExecuteScalar() +161
DButility.SqlHelper.ExecuteScalar(String connectionString, CommandType cmdType, String cmdText, SqlParameter[] commandParameters) in E:\MyCase\DButility\SqlHelper.cs:96
SQLProfileDAL.CasketProfileProvider.CreateProfileForUser(Int32 accountID, String accountName, Boolean isAuthenticated, String appName) in E:\MyCase\SQLProfileDAL\CaseProfileProvider.cs:301
Profile.CasketProfileProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) in E:\MyCase\Profile\CasketProfileProvider.cs:110
System.Configuration.SettingsBase.SaveCore() +469
System.Configuration.SettingsBase.Save() +119
System.Web.Profile.ProfileBase.SaveWithAssert() +46
System.Web.Profile.ProfileBase.Save() +86
Cart.Page_Load(Object sender, EventArgs e) in e:\MyCase\Web\Cart.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +31
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +68
System.Web.UI.Control.OnLoad(EventArgs e) +88 展开
语句已终止。
源错误:
行 94: {
行 95: PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
行 96: object val = cmd.ExecuteScalar();////出错
行 97: cmd.Parameters.Clear();
行 98: return val;
堆栈跟踪:
[SqlException (0x80131904): 违反了 PRIMARY KEY 约束 'PK_TBL_Profiles'。不能在对象 'dbo.TBL_Profiles' 中插入重复键。
语句已终止。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +52
System.Data.SqlClient.SqlDataReader.get_MetaData() +130
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +371
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +45
System.Data.SqlClient.SqlCommand.ExecuteScalar() +161
DButility.SqlHelper.ExecuteScalar(String connectionString, CommandType cmdType, String cmdText, SqlParameter[] commandParameters) in E:\MyCase\DButility\SqlHelper.cs:96
SQLProfileDAL.CasketProfileProvider.CreateProfileForUser(Int32 accountID, String accountName, Boolean isAuthenticated, String appName) in E:\MyCase\SQLProfileDAL\CaseProfileProvider.cs:301
Profile.CasketProfileProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) in E:\MyCase\Profile\CasketProfileProvider.cs:110
System.Configuration.SettingsBase.SaveCore() +469
System.Configuration.SettingsBase.Save() +119
System.Web.Profile.ProfileBase.SaveWithAssert() +46
System.Web.Profile.ProfileBase.Save() +86
Cart.Page_Load(Object sender, EventArgs e) in e:\MyCase\Web\Cart.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +31
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +68
System.Web.UI.Control.OnLoad(EventArgs e) +88 展开
展开全部
如果报的错有PK,说明是违返了主健约束,
PK是指primary key,主健的意思.
主健那一列是不可以有重复值的,并且不能为空。如果该列已有一个值是A,那在插入一个A的话就会报错~
例:如果列1是主健
insert into 表 ( 列1,列2 ) values (1,'你好') 如果这句已执行成功
再插入一行
insert into 表 ( 列1,列2 ) values (1,'hi') 这句执行就会报错。因为
主健中已经存在1这个值了.不可重复
楼主是在C#连接数据库并执行SQL语句。同样不能违返SQL的约束啊
PK是指primary key,主健的意思.
主健那一列是不可以有重复值的,并且不能为空。如果该列已有一个值是A,那在插入一个A的话就会报错~
例:如果列1是主健
insert into 表 ( 列1,列2 ) values (1,'你好') 如果这句已执行成功
再插入一行
insert into 表 ( 列1,列2 ) values (1,'hi') 这句执行就会报错。因为
主健中已经存在1这个值了.不可重复
楼主是在C#连接数据库并执行SQL语句。同样不能违返SQL的约束啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询