
May 12th, 2008, 10:37 AM
|
 |
bawk bawk bawk
|
|
Join Date: Mar 2006
Location: Dothan, AL
|
|
|
ASP.Net/VB.Net - INSERT Statement conflicted
Time for me to pick your brains again. Forgive me tho i am just starting to learn asp.net and i am trying to learn from a book and i follow what it says and sometimes what it says and what actually happens doesn't remain consistent. For example, i am receiving an error that i have no clue what it means, i have used the Google function to help figure it out but it wasn't able to produce any results. So any thoughts from the ASP community would be great!
the error
Code:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_HelpDesk_employees'. The conflict occurred in database 'intranet', table 'employees', column 'EmployeeID'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_HelpDesk_employees'. The conflict occurred in database 'intranet', table 'employees', column 'EmployeeID'.
The statement has been terminated.
Source Error:
Line 45: objCmd.Parameters.Add("@StatusID", 1)
Line 46: objConn.Open()
Line 47: objCmd.ExecuteNonQuery()
Line 48: objConn.Close()
Line 49: Response.Redirect("helpdesk.aspx")
Source File: D:\wwwroot\Sites\Intranet\helpdesk.aspx Line: 47
Stack Trace:
[SqlException (0x80131904): INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_HelpDesk_employees'. The conflict occurred in database 'intranet', table 'employees', column 'EmployeeID'.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +925466
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +800118
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +149
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
ASP.helpdesk_aspx.SubmitHelpDesk(Object s, EventArgs e) in D:\wwwroot\Sites\Intranet\helpdesk.aspx:47
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
the code
Code:
Sub SubmitHelpDesk(ByVal s As Object, ByVal e As EventArgs)
objCmd = New SqlCommand("INSERT INTO HelpDesk (EmployeeId, StationNumber, CategoryID, SubjectID, Description, StatusID) VALUES (@EmployeeID, @StationNumber, @CategoryID, @SubjectID, @Description, @StatusID)", objConn)
objCmd.Parameters.Add("@EmployeeID", 5)
objCmd.Parameters.Add("@StationNumber", txtStationNum.Text)
objCmd.Parameters.Add("@CategoryID", ddlCategory.SelectedItem.Value)
objCmd.Parameters.Add("@SubjectID", ddlSubject.SelectedItem.Value)
objCmd.Parameters.Add("@Description", txtDescription.Text)
objCmd.Parameters.Add("@StatusID", 1)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
Response.Redirect("helpdesk.aspx")
End Sub
|