CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.commerce_starter_kit Tags:
Item Type: NewsGroup Date Entered: 5/27/2005 2:23:12 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 12 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
TexasSkybolt
Asp.Net User
Problem with Finalizing the Orders.5/27/2005 2:23:12 AM

0/0

I've been having a strange error and hoped that maybe you folks could help me out.  When I attmept to finalize the order and run the OrdersAdd SPROC, I get the following error:

INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_Orders_Customers'. The conflict occurred in database 'Commerce', table 'Tmp_CMRC_Customers', column 'CustomerID'. 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_Orders_Customers'. The conflict occurred in database 'Commerce', table 'Tmp_CMRC_Customers', column 'CustomerID'. The statement has been terminated.

Source Error:

Line 207:            ' Open the connection and execute the Command
Line 208:            myConnection.Open()
Line 209:            myCommand.ExecuteNonQuery()
Line 210:            myConnection.Close()

Following is the Code.  By the way, you will see that I've commented out some of the code and the error given was as with the code listed below.

<code>

Private Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles SubmitBtn.Click

 

Dim cart As ASPNET.StarterKit.Commerce.ShoppingCartDB = New ASPNET.StarterKit.Commerce.ShoppingCartDB()

' Calculate end-user's shopping cart ID

Dim cartId As String = cart.GetShoppingCartId()

' Calculate end-user's customerID

Dim customerId As Integer = CInt(User.Identity.Name)

If (Not cartId Is Nothing) And (Not customerId < 0) Then

' Place the order

Dim ordersDatabase As ASPNET.StarterKit.Commerce.OrdersDB = New ASPNET.StarterKit.Commerce.OrdersDB

Dim orderId As Integer = ordersDatabase.PlaceOrder(customerId, cartId)

Label1.Text = cartId

Label2.Text = customerId

'Update labels to reflect the fact that the order has taken place

'Header.Text = "Check Out Complete!"

'Message.Text = "<b>Your Order Number Is: </b>" & orderId

'SubmitBtn.Visible = False

End If

End Sub

The following code is from the OrdersDB Namespace:

Public Function PlaceOrder(ByVal customerID As Integer, ByVal cartID As String) As Integer

' Create Instance of Connection and Command Object

Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

Dim myCommand As SqlCommand = New SqlCommand("CMRC_OrdersAdd", myConnection)

' Mark the Command as a SPROC

myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC

Dim parameterCustomerID As SqlParameter = New SqlParameter("@CustomerID", SqlDbType.Int, 4)

parameterCustomerID.Value = customerID

myCommand.Parameters.Add(parameterCustomerID)

Dim parameterCartID As SqlParameter = New SqlParameter("@CartID", SqlDbType.NVarChar, 50)

parameterCartID.Value = cartID

myCommand.Parameters.Add(parameterCartID)

Dim parameterShipDate As SqlParameter = New SqlParameter("@ShipDate", SqlDbType.DateTime, 8)

parameterShipDate.Value = CalculateShippingDate(customerID, cartID)

myCommand.Parameters.Add(parameterShipDate)

Dim parameterOrderDate As SqlParameter = New SqlParameter("@OrderDate", SqlDbType.DateTime, 8)

parameterOrderDate.Value = DateTime.Now

myCommand.Parameters.Add(parameterOrderDate)

Dim parameterOrderID As SqlParameter = New SqlParameter("@OrderID", SqlDbType.Int, 4)

parameterOrderID.Direction = ParameterDirection.Output

myCommand.Parameters.Add(parameterOrderID)

' Open the connection and execute the Command

myConnection.Open()

myCommand.ExecuteNonQuery()

myConnection.Close()

' Return the OrderID

Return CInt(parameterOrderID.Value)

End Function

Following is the Code from the SPROC

CREATE Procedure CMRC_OrdersAdd
(
    @CustomerID int,
    @CartID     nvarchar(50),
    @OrderDate  datetime,       
    @ShipDate   datetime,
    @OrderID    int OUTPUT
)
AS

/* BEGIN TRAN AddOrder */

/* Create the Order header */
INSERT INTO CMRC_Orders
(
    CustomerID,
    OrderDate,
    ShipDate
)
VALUES
(  
    @CustomerID,
    @OrderDate,
    @ShipDate
)

/* SELECT
    @OrderID = @@Identity   
*/
/* Copy items from given shopping cart to OrdersDetail table for given OrderID*/
/* INSERT INTO CMRC_OrderDetails
(
    OrderID,
    ProductID,
    Quantity,
    UnitCost
)

SELECT
    @OrderID,
    CMRC_ShoppingCart.ProductID,
    Quantity,
    CMRC_Products.UnitCost

FROM
    CMRC_ShoppingCart
  INNER JOIN CMRC_Products ON CMRC_ShoppingCart.ProductID = CMRC_Products.ProductID
 
WHERE
    CartID = @CartID

/* Removal of  items from user's shopping cart will happen on the business layer*/
EXEC CMRC_ShoppingCartEmpty @CartID
*/
/*COMMIT TRAN AddOrder*/
GO


</code>


I've verified that the CustomerID and CartID are correct.  Any help would be greatly appreciated.

Regards,
Seth Fuller
TexasSkybolt

Deepti Kalakond
Asp.Net User
Re: Problem with Finalizing the Orders.5/27/2005 10:59:52 AM

0/0

Hello there,

You have received the following error as the Inert statement on the Orders table is conflicting with the foreign key constraint defined on the table. There might be a foreign key constraint defined on the CustomerID column in the Orders table that is referencing the CustomerID column in the Customers table. Hence, you are receiving an error when you are trying to insert an order with a new CustomerID (that does not exist in the Customers table) in the Orders table.


Durga Deepti Kalakonda
MCAD (.NET)
TexasSkybolt
Asp.Net User
Re: Problem with Finalizing the Orders.5/27/2005 1:03:16 PM

0/0

Deepti,
Thanks.  I'll take a look at the table structure tonight.  I have verified that the CustomerID does exist in the Customers table and that it is correct.  Thus, I'm not sure as to why the conflict.  But, thanks for the suggestion.
Regards,
Seth
jakeburkey
Asp.Net User
Re: Problem with Finalizing the Orders.5/27/2005 9:00:50 PM

0/0

Seth -

As has been mentioned, your program is attempting to insert a value in the CustomerID field in the CMRC_Orders table, for which there is no corresponding value in the CustomerID field in the CMRC_Customers table.  Because the primary key for the CMRC_Customers table (i.e. CustomerID) is a foreign key in the CMRC_Orders table, the only values that may be inserted in the CustomerID field in the CMRC_Orders table are values that exist in the CMRC_Customers table or nulls.

You may view the foreign key relationships in your database by opening the Enterprise Manager, then opening the table of interest (in this case, CMRC_Orders) in design view (right click on table and choose Design Table from context menu).  Once the table is open in design view, click on the Manage Relationships button on the toolbar at the top of the window.  A dialog box will open showing the relationships and foreign key constraints.

I don't have time to study your code, but my guess is that you have modified the original code, with the result that it is attempting to record an order for a customer that has not yet been registered.  Otherwise, the CustomerID value for that customer would already be in the CMRC_Customers table.

jake
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Web Database Applications with PHP and MySQL: Building Effective Database-Driven Web Sites Authors: Hugh E. Williams, David Lane, David John Lane, Pages: 796, Published: 2004
SQL: The Complete Reference Authors: James R. Groff, Paul N. Weinberg, Pages: 1050, Published: 2002
The Design of Sites: Patterns, Principles, and Processes for Crafting a Customer-centered Web Experience Authors: Douglas K. Van Duyne, James A. Landay, Jason I. Hong, Pages: 762, Published: 2002
SQL from the Ground Up Authors: Mary Pyefinch, Pages: 510, Published: 1999
C# Unleashed Authors: Joseph Mayo, Pages: 794, Published: 2002
Qualified Domestic Relations Order Handbook Authors: Gary A. Shulman, Pages: 1168, Published: 2006
Robot Builder's Sourcebook: Over 2500 Sources for Robot Parts Authors: Gordon McComb, Pages: 711, Published: 2002
Strategies for Protecting National Critical Infrastructure Assets: A Focus on Problem-Solving Authors: John Sullivant, Pages: 607, Published: 2007

Web:
20 – CONSTRUCTION CHANGE ORDERS 20.4 – FINALIZING CHANGE ORDERS 20.4 – FINALIZING CHANGE ORDERS. Revised:. February 13, 2008. PURPOSE ... After completing negotiations for a change order, the CM must finalize the ...
Finalizing caswell order - Plating Powder Coating Buffing ... I am about to start a small garage anodizing side project. on Budget Anodize & Chrome Stripper $8.00 Anodize & Chrome Stripper - Caswell.
Finalizing the batting order Photo - Buzznet Finalizing the batting order. ... Finalizing Your Order Points There are two options for finalizing order points on your system. Inventory Master can send them in the Flex-Report IMASTER3 for you to check over before ...
Welcome to the Shark Cage If all the details are correct and you are satisfied with the total cost of your order, you can now submit your payment details to finalize your order. ...
HerpSupplies.com - Reptile Supplies, Vivarium, Reptile Accessories ... In a small number of cases, you may have problems finalizing an order if you have cookies turned off AND your Internet provider uses dynamic IP addressing. ...
Finalizing Disks and/or Saving Tracks -- Questions - Club CDFreaks ... A quick question about "finalizing" and "saving tracks" in order to insure playback .... Problem with finalizing DVD disks, knir, Nero SDK Discussion Forum ...
Safari Books Online - 0672323095 - MySQL™ and JSP™ Web ... ... developers encounter unique problems when building web applications that require intense database ... Implementing Business Logic > Finalizing the Order ...
Brown Paper Tickets - The first and only fair-trade ticketing service! Also includes a "1" if Stage 3 is required before finalizing the order (ie. physical ... May be blank when finalizing orders containing only free tickets. ...
AVIATION-PHOTOGRAPHY.nl - Boeing and Singapore Airlines Finalize ... Boeing and Singapore Airlines Finalize Dreamliner Order ... Singapore Airlines' order for these 20 Dreamliners brings the total orders for the 787 family to ...

Videos:
Picotto vs Papini - Gonna Get Ya Picotto Vs Papini - Gonna Get Ya - Out Now! Already an Ibiza Classic, 'Gonna Get Ya' is the monstrous bootleg of Mauro Picotto's legendary Gonna Get...
DGM - Black Order Plays D&D "Why the cast of D. Gray-Man should never play Dungeons and Dragons" Very old thing I made, finally got the nerve to finalize it
Fall of the Black Flight This is the "grande-finale" of my Blackwing Lair series. It contains the history behind Blackrock Mountain, a quick walk through Blackwing Lair and...
Divorce Advice : Finalizing a Divorce In order to finalize a divorce, a judgment must be rendered and presented to court on such issues as distribution of assets and liabilities of both p...
UPtown Center A special meeting of the University Place City Council took place May 17, 2007. Called to order by Mayor Gerald Gehring, the purpose was to finalize,...
Infrared Rays Infrared: its name says it, below the red one, is underneath in which to frequency it is which can detect our eyes. As it demonstrates the video to i...
CNC Stomp Pad 3 | SheetCAM | Learn CNC Plasma Cutting | CAM Programming | G-Code | CNC DIY | CAM | CNC Machining | CNC Cutting | CNC Book | CNC Video | DXF File | DWG File | CNC Files | CNC Patterns Here we set the CAM Programming parameters in SheetCam. Next we finalize the G-Code for the project. You also get a quick look at some CNC Post-Proce...
Accounting: Income Statement Make sure you don't make any mistakes when calculating you income statement! Learn the order of finalizing your account statements.
Biden, Powell, and others using the old Bush/Terror tactic They say Whorebama will be tested, with Powell giving specific dates of the so called unknown event. Just like september 11 2001 they know exactly wh...
Sara's adoption decree Our daughter Sara and the day we met with the probate judge in order to finalize her adoption. Nossa filha, Sara Olivia, e o dia em que encontramos ...




Search This Site:










creating and using an object between pages

security issue for stored documents

my pws kit working nicely.

popup window-like in asp.net?

happy halloween *free skin*

updating module setting takes ages

controls, <register namespace="dll.mycontrol" assembly = "swapyourvacationhome"> in vs2005

removing numbers from the end of a string

upload jpeg, gif to webserver

moving labels and text boxes anywhere i want to using vs2008express

adding/opening projects to and from team foundation server?

signin cssclass??

error unrecognized attribute 'requirepermission' ... web.config 6

help with menu control and sitemap please?

visual web developer 2005: "page cannot be displayed"

windows authentication breaks debug?

convert asp to asp.net 2.0

globally adding attributes to buttons

i configured a new application but now i have lost my code

resx files

remember me doesn't always work

extending search function question

so did sp1 actually fix anything in vs 2005? more issues with imagebutton in a panel...

suggestions on tools,. 3rd party, etc. for equipment scheduling application

dnn 3.1 upgrade trouble

i broke it....

web service user name and password protection

how do you change dbo to another user

treeview + style

magicspacer curiosity...

 
All Times Are GMT