Converting nvarchar value '3001822585' overflows int column

I use the following command to import an Excel file into SQL Server.

An Excel file has all the values ​​as a string. I can import the file except Barcode, SalePriceand Price2. I get an error

Converting nvarchar value '3001822585' (barcode) overflows int column

the code:

         SqlCommand sqlcmd = new SqlCommand
         (@"MERGE Inventory AS target
         USING (SELECT
            LocalSKU, ItemName, QOH, Price, Discontinued,Barcode, Integer2
            ,Integer3, SalePrice, SaleOn, Price2 FROM @source)
            AS Source ON (Source.LocalSKU = target.LocalSKU)
           WHEN MATCHED THEN
           UPDATE 
           SET ItemName = source.ItemName,
           Price = source.Price,
           Discontinued = source.Discontinued,
           Barcode = source.Barcode,
           Integer2 = source.Integer2,
           Integer3 = source.QOH,
           SalePrice = source.SalePrice,
           SaleOn = source.SaleOn,
           Price2 = source.Price2;", sqlconn);

           SqlParameter param;
           param = sqlcmd.Parameters.AddWithValue("@source", dr);
           param.SqlDbType = SqlDbType.Structured;
           param.TypeName = "dbo.InventoryType";

           sqlconn.Open();
           sqlcmd.ExecuteNonQuery();
           sqlconn.Close();

Database::

 LocalSKU varchar(200),
 ItemName varchar(200),
 QOH int,
 Price decimal(19,4),
 Discontinued bit,
 Barcode int,
 Integer2 int,
 Integer3 int,
 SalePrice decimal(19,4),
 SaleOn bit,
 Price2 decimal(19,4)

dbo.InventoryType:

   CREATE TYPE [dbo].[InventoryType] AS TABLE
   (
      [LocalSKU] [varchar](200) NOT NULL,
      [ItemName] [varchar](200) NULL,
      [QOH] [int] NULL,
      [Price] [decimal](19, 4) NULL,
      [Discontinued] [bit] NULL,
      [Barcode] [varchar](25) NULL,
      [Integer2] [int] NULL,
      [Integer3] [int] NULL,
      [SalePrice] [decimal](19, 4) NULL,
      [SaleOn] [bit] NULL,
      [Price2] [decimal](19, 4) NULL
   )
   GO

How to pass data type in table value parameter? An example will be appreciated.

+4
source share
2 answers

Use unsignedInt data type.

int range - 4 bytes, -2,147,483,648 to +2,147,483,647 
unsignedInt range - 0 to 4,294,967,295 

- 3001822585 max int 2,147,483,647

Edit

unigned int SQL Server, MySQL . SQL Server bigINT

bigInt range - 8 bytes -2^63 to 2^63-1 

Barcode bigInt. , , .

+7

SQl:

SELECT max( Mother_ID)+1 FROM Mother

http://i.stack.imgur.com/ACKAW.jpg Msg 248, 16, 1, 1 nvarchar '182512900911500120' int.

, 182512900911500120 int. bigint, .

.

SELECT max(convert(bigint,Mother_ID))+1 as MID FROM Mother

http://i.stack.imgur.com/ZLSNR.jpg 182512900911500121

0

Source: https://habr.com/ru/post/1537329/


All Articles