Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error:-fix this Error Conversion failed when converting the nvarchar value 'String or binary data would be truncated.' to data type int.

My Table:

ID int Unchecked
ColName varchar(255) Unchecked
Title varchar(255) Unchecked
DataSource varchar(255) Checked
ControlID int Unchecked
MaxLength int Unchecked
Width int Unchecked
Height int Unchecked
IsMandatory bit Unchecked
CommandArea char(1) Checked
CreatedBy int Checked
CreatedOn datetime Checked
UpdatedOn datetime Checked
Status bit Checked
UpdatedBy int Checked
IPAddress varchar(1) Checked



My store-Procedures:


SQL
ALTER PROCEDURE [dbo].[spAddVoucherReachCols]
    @xml xml, @error varchar(1000) output AS
BEGIN BEGIN TRY
INSERT INTO VoucherReachCols (ColName,Title ,DataSource ,ControlID ,MaxLength ,Width ,Height ,IsMandatory,CreatedBy,CreatedOn,UpdatedOn,Status,UpdatedBy,IPAddress )
SELECT N.value('(Title)[1]', 'Varchar(MAX)') ,N.value('(ColName)[1]', 'Varchar(MAX)') ,N.value('(DataSource)[1]', 'Varchar(MAX)') ,N.value('(ControlID)[1]', 'NVarchar(MAX)') ,
N.value('(MaxLength)[1]', 'NVarchar(MAX)') ,N.value('(Width)[1]', 'NVarchar(MAX)') ,
N.value('(Height)[1]', 'NVarchar(MAX)') ,N.value('(IsMandatory)[1]', 'Varchar(MAX)'),N.value('(CreatedBy)[1]', 'int'),
GetDate(),GetDate(),1,N.value('(UpdatedBy)[1]', 'int'),
N.value('(IPAddress)[1]','Varchar(20)')  FROM @XML.nodes('/Table/VoucherReachCols') as T(N);
END TRY
BEGIN CATCH SET @Error = ERROR_NUMBER() + ' ' + ERROR_MESSAGE();
END CATCH
END
Posted

I hope you are trying to convert the string to int. check your xml node values before inserting
 
Share this answer
 
Comments
Nishant.Chauhan80 24-Nov-14 2:11am    
where ? Before @xml in above store-p
Yes, validate the below filed values in XML.

ID int Unchecked
ControlID int Unchecked
MaxLength int Unchecked
Width int Unchecked
Height int Unchecked
CreatedBy int Checked
UpdatedBy int Checked

it cannot be a string values.

you have sample XML then put a breakpoint and debug.

http://msdn.microsoft.com/en-us/library/yet1b7by%28VS.80%29.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900