Conversion failed when converting the nvarchar value 'abc' to data type int in nopcommerce 4.3

0

I want to search GTIN option in admin product list. So, for that I am providing GTIN value in ProductLoadAllPaged store procedure. Now, when I search GTIN value from product list at that time throw datatable error and from console application get message that

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting the nvarchar value 'abc' to data type int.

Here is store procedure added code,

ALTER PROCEDURE [dbo].[ProductLoadAllPaged]
(
    @GTIN nvarchar(50) --AWAZ
)
AS
BEGIN
    .....
    
    --filter by vendor
    IF @VendorId > 0
    BEGIN
        SET @sql = @sql + '
        AND p.VendorId = ' + CAST(@VendorId AS nvarchar(max))
    END
    
    --AWAZ
    IF @GTIN is not null
    BEGIN
        SET @sql = @sql + '
        AND p.Gtin = ' +  @GTIN             
    END

    --filter by warehouse
    IF @WarehouseId > 0
    BEGIN
        --we should also ensure that 'ManageInventoryMethodId' is set to 'ManageStock' (1)
        --but we skip it in order to prevent hard-coded values (e.g. 1) and for better performance
        SET @sql = @sql + '
        AND  
            (
                (p.UseMultipleWarehouses = 0 AND
                    p.WarehouseId = ' + CAST(@WarehouseId AS nvarchar(max)) + ')
                OR
                (p.UseMultipleWarehouses > 0 AND
                    EXISTS (SELECT 1 FROM ProductWarehouseInventory [pwi]
                    WHERE [pwi].WarehouseId = ' + CAST(@WarehouseId AS nvarchar(max)) + ' AND [pwi].ProductId = p.Id))
            )'
    END
    
    .....
END
sql
sql-server
stored-procedures
nopcommerce
sqlexception
asked on Stack Overflow Dec 14, 2020 by s.k.Soni

1 Answer

2

so seems like you need to chnage this part of code :

   --AWAZ
    IF @GTIN is not null
    BEGIN
        SET @sql = @sql + '
        AND p.Gtin like ''%' + @GTIN + '%'''            
    END
answered on Stack Overflow Dec 14, 2020 by eshirvana

User contributions licensed under CC BY-SA 3.0