I have a stored procedure to insert into two tables at once.
However, when I add the order from the .net page, the first insert statement works and the record is added but the second fails with the following error:
I have looked up this error on google and dont understand what I need to do to resolve it.
The @@Identity value is to populate the OrderID of the OrderDetails table. The OrderID in the OrderDetails table datatype is int and is a FK.
The Product field in the OrderDetails table datatype is also set to int as it is linked to the Products table. FK also.
The Quantity field is set to int, as its just a number. No FK.
Code:
USE [PhoenixSQL]
GO
/****** Object: StoredProcedure [dbo].[AddOrder] Script Date: 03/31/2011 22:51:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddOrder]
(
@TraderID int,
@OrderNumber nvarchar(50),
@InvoiceNumber nvarchar(50),
@InvoiceDate datetime,
@Carriage decimal(18,2),
@Product int,
@Quantity int,
@UnitPrice decimal (18,3)
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @OrderID int
INSERT INTO dbo.Orders (TraderID, OrderNumber, InvoiceNumber, InvoiceDate, Carriage)
VALUES (@TraderID, @OrderNumber, @InvoiceNumber, @InvoiceDate, @Carriage)
SELECT @OrderID = @@IDENTITY
INSERT INTO dbo.OrderDetails (OrderID, Product, Quantity, UnitPrice)
VALUES (@OrderID, @Product, @Quantity, @UnitPrice)
END
However, when I add the order from the .net page, the first insert statement works and the record is added but the second fails with the following error:
Code:
Arithmetic overflow error converting expression to data type nvarchar.
Conversion failed when converting the nvarchar value 'A' to data type int.
I have looked up this error on google and dont understand what I need to do to resolve it.
The @@Identity value is to populate the OrderID of the OrderDetails table. The OrderID in the OrderDetails table datatype is int and is a FK.
The Product field in the OrderDetails table datatype is also set to int as it is linked to the Products table. FK also.
The Quantity field is set to int, as its just a number. No FK.