Click here to Skip to main content
12,253,114 members (44,413 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB SQL-Server VB.NET
Hi all

i am getting the below error in my try catch block
Try
           If para_name.Count = para_val.Count Then
               cmd = New SqlCommand(sp_name, cn)
               cmd.CommandType = CommandType.StoredProcedure
               For i = 0 To para_name.Count - 1
                   cmd.Parameters.AddWithValue(para_name(i), para_val(i))
               Next
               cmd.ExecuteNonQuery()
           Else
               MsgBox("Fill All Parameter....")
           End If
       Catch ex As Exception
       End Try
Error converting data type nvarchar to decimal.
i don't have any column with datatype nvarchar..please tell me what is the problem..

below is the SP wrote for it:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
 
ALTER PROCEDURE [dbo].[Add_salary]
	(
	
	@month_no varchar (50),
	@s_year int ,
	@emp_code int ,
	@basic numeric(18, 0),
	@da numeric(18, 0),
	@hra numeric(18, 0),
	@ca numeric(18, 0),
	@bp numeric(18, 0),
	@outfit numeric(18, 0),
	@bonus numeric(18, 0),
	@overseas numeric(18, 0),	
	@gross numeric(18, 0),
	@tot_ded numeric(18, 0),
	@netsal numeric(18, 0),
	@remark varchar(50)
	)	
AS
	insert into Salary (month_no,s_year,emp_code,basic,da,hra ,ca,bp,outfit,bonus,overseas,gross,tot_ded,netsal,remark) 
    values (@month_no,@s_year,@emp_code,@basic,@da,@hra ,@ca,@bp,@outfit,@bonus,@overseas,@gross,@tot_ded,@netsal,@remark)
	RETURN
Posted 28-Sep-12 23:46pm
Code-Hunt7.1K
Edited 30-Sep-12 23:11pm
v4
Comments
Chris Maunder 29-Sep-12 6:36am
   
It's probably an issue with the stored proc you're calling. Please update your question and add the code for the sproc so we can help
CloudWebi 29-Sep-12 6:38am
   
Where is the stored procedures? If you can do convert(decimal, [column]) on the stored procedure this will be the best option for now.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this on your stored procedure

CAST(([yourcolumn]) AS DECIMAL(12,8))
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi snehasish nandy,

Here the user don,t Know Sal as a Number(Basically they consider Decimal For exe : 105.50, )
after calculating Da,Ta it will get the Decimal so that it is raising an error.
So that you can declare all Currency(Money ) related fields as Decimal.

Note : Generally DA,TA, Allowances,.... gives % upon Basic Salary .Suppose Basic Salary
not multiplier of 100/10 it will get fractions like Decimal .


i hop you will get an idea Now.
  Permalink  
Comments
snehasish nandy 1-Oct-12 5:38am
   
@Unareshraju: same error i m getting
Error converting data type nvarchar to int.
changed the datatype also but still it's comming
Unareshraju 1-Oct-12 5:51am
   
instead of numeric(18, 0) change into Decimal(18,2) and
instead of varchar (50) change into nvarchar(50) after that
give like this

values ('@month_no',@s_year,@emp_code,@basic,@da,@hra ,@ca,@bp,@outfit,@bonus,@overseas,@gross,@tot_ded,@netsal,'@remark')

Note: nvarchar should in singlecote

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100