.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 12th, 2008, 10:37 AM
RChicken's Avatar
RChicken RChicken is offline
bawk bawk bawk
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Dothan, AL
Posts: 369 RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 7556 Folding Title: Novice Folder
Time spent in forums: 4 Days 4 h 30 m 40 sec
Reputation Power: 60
Send a message via ICQ to RChicken Send a message via AIM to RChicken Send a message via MSN to RChicken Send a message via Yahoo to RChicken Send a message via XFire to RChicken
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

Reply With Quote
  #2  
Old May 12th, 2008, 12:10 PM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,467 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 1 h 41 m 47 sec
Reputation Power: 519
What this error is saying is that you are trying to insert a record into the HelpDesk table with an EmployeeID that does not exist in the Employees table. HelpDesk has a Foreign Key defined which prevents this -- and prevents inconsistent data.

This is why you should always wrap the execution of SQL commands in TRY CATCH blocks.
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. Not FDIC insured

Reply With Quote
  #3  
Old May 12th, 2008, 12:32 PM
RChicken's Avatar
RChicken RChicken is offline
bawk bawk bawk
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Dothan, AL
Posts: 369 RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)RChicken User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 7556 Folding Title: Novice Folder
Time spent in forums: 4 Days 4 h 30 m 40 sec
Reputation Power: 60
Send a message via ICQ to RChicken Send a message via AIM to RChicken Send a message via MSN to RChicken Send a message via Yahoo to RChicken Send a message via XFire to RChicken
Quote:
Originally Posted by Wolffy
What this error is saying is that you are trying to insert a record into the HelpDesk table with an EmployeeID that does not exist in the Employees table. HelpDesk has a Foreign Key defined which prevents this -- and prevents inconsistent data.

This is why you should always wrap the execution of SQL commands in TRY CATCH blocks.



ahhhhhhhhhhhhhhhhhhhhh!?!?!??!?!

here is the problem
objCmd.Parameters.Add("@EmployeeID", 5)
here is the solution
objCmd.Parameters.Add("@EmployeeID", 1)

that makes me mad cause i changed that and it threw the same error.. but anyway, thanks it works now.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > ASP.Net/VB.Net - INSERT Statement conflicted


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway