Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion failed when converting the nvarchar value 'A' to data type

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I have a stored procedure to insert into two tables at once.

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.


 
This is a SQL question, not a .NET issue eventhoug you are calling the sql from an ASP.NET page.

The first thing to check is the data you are passing to the SP, and check all DataTypes for the columns you are trying to insert into to be sure they are what you expect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top