TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pippa Daly
NA
28
850
Problem with Primary key in database when using web forms
Feb 10 2018 1:00 PM
I'm getting an issue when I try to input data into a web page. However the issue is with my primary/foreign key in the database. Any help would be much appreciated.
Error message:
Error:System.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "UserIDfk". The conflict occurred in database "\\MAC\HOME\DOCUMENTS\COLLEGE\4TH YEAR\FYP\ITERATION 1\FYP-NEW\FYP-PARKWAY\FYP-PARKWAY\APP_DATA\USERDATA.MDF", table "dbo.Registration", column 'UserID'. The statement has been terminated. at System.Data.SqlClient.SqlConnection.onerror(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.onerror(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(Runbehavior runbehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, Runbehavior runbehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(Commandbehavior cmdbehavior, Runbehavior runbehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(Commandbehavior cmdbehavior, Runbehavior runbehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at FYP_ParkWay.ListSpace.Button1_Click(Object sender, EventArgs e) in \\Mac\Home\Documents\College\4th Year\FYP\Iteration 1\FYP-NEW\FYP-ParkWay\FYP-ParkWay\ListSpace.aspx.cs:line 30 ClientConnectionId:dbdeb098-62a6-45bf-960b-374be8a4e13f Error Number:547,State: 0,Class:16
My primary key is:
CREATE
TABLE
[dbo].[Registration] (
[UserID]
INT
IDENTITY (1, 1)
NOT
NULL
,
[
Name
]
NCHAR
(20)
NULL
,
[Surname]
NCHAR
(20)
NULL
,
[Email]
NCHAR
(30)
NULL
,
[Address]
NCHAR
(50)
NULL
,
[Phone] NVARCHAR (50)
NULL
,
[
Password
]
NCHAR
(30)
NULL
,
CONSTRAINT
[pk_UserID]
PRIMARY
KEY
CLUSTERED ([UserID]
ASC
)
)
The insert statement in which its referring is:
SqlConnection conn =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"RegistrationConnectionString"
].ConnectionString);
conn.Open();
String insertQuery =
"insert into ListSpace (Area,Date,StartTime,EndTime,Picture) values(@area, @date, @startTime, @endTime, @picture)"
;
SqlCommand com =
new
SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue(
"@area"
, ddlArea.Text);
com.Parameters.AddWithValue(
"@date"
, cdrDate.SelectedDate);
com.Parameters.AddWithValue(
"@startTime"
, ddlStart.Text);
com.Parameters.AddWithValue(
"@endTime"
, ddlEnd.Text);
com.Parameters.AddWithValue(
"@picture"
, updPicture.FileBytes);
com.ExecuteNonQuery();
Reply
Answers (
1
)
How to import sql server database to wamp phpmyadmin
who can we print numbers in ascii