c# - Cannot convert datatype nvarchar to numeric -
i import data from excel file sql server database following query. excel file has values string types ('
before every cells).
i error when import it."cannot convert datatype nvarchar numeric"
if remove 2 columns saleprice , price2 importing, import successful.
the datatypes of table
create type [dbo].[inventorytype] 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
the query using is:
sqlcommand sqlcmd = new sqlcommand (@"merge inventory target using (select localsku, itemname, qoh, price, discontinued, barcode, integer2, integer3, saleprice, saleon, price2 @source) source on (source.localsku = target.localsku) when matched 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();
one thing keep in mind may have invalid data in given column that's throwing error(s). example if have numeric column , have letters or inproperly formatted numeric values, error thrown. check values in cells aren't correct first. includes trailing or leading spaces well.
Comments
Post a Comment