在 nopcommerce 4.3 中将 nvarchar 值 'abc' 转换为数据类型 int 时转换失败
Conversion failed when converting the nvarchar value 'abc' to data type int in nopcommerce 4.3
我想在管理产品列表中搜索 GTIN 选项。因此,为此我在 ProductLoadAllPaged 存储过程中提供了 GTIN 值。现在,当我当时从产品列表中搜索 GTIN 值时抛出数据表错误,并从控制台应用程序中获取消息
System.Data.SqlClient.SqlException (0x80131904): 将 nvarchar 值 'abc' 转换为数据类型 int 时转换失败。
这是存储过程添加的代码,
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
看来您需要更改这部分代码:
--AWAZ
IF @GTIN is not null
BEGIN
SET @sql = @sql + '
AND p.Gtin like ''%' + @GTIN + '%'''
END
我想在管理产品列表中搜索 GTIN 选项。因此,为此我在 ProductLoadAllPaged 存储过程中提供了 GTIN 值。现在,当我当时从产品列表中搜索 GTIN 值时抛出数据表错误,并从控制台应用程序中获取消息
System.Data.SqlClient.SqlException (0x80131904): 将 nvarchar 值 'abc' 转换为数据类型 int 时转换失败。
这是存储过程添加的代码,
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
看来您需要更改这部分代码:
--AWAZ
IF @GTIN is not null
BEGIN
SET @sql = @sql + '
AND p.Gtin like ''%' + @GTIN + '%'''
END