Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello,

I am trying to pass some Table valued parameters to a stored procedure. I created the type like:
SQL
CREATE TYPE [dbo].[TestTableType] AS TABLE(
	[Date] [date] NULL,
	[Ref] [varchar](50) NULL,
	[Amount] [decimal](20, 4) NULL
)
GO

I passed the parameter to the stored procedure by the following code:
SQL
Create PROCEDURE [dbo].[TestProcedure]
(@tvp dbo.TestTableType READONLY)
AS
BEGIN  
   select * from @tvp; 
END

I am passing the parameter to the procedure by the following portion of the code:
C#
List<SqlParameter> paramList = new List<SqlParameter>();
SqlParameter tvpParam = new SqlParameter("@tvp", dr);
tvpParam.SqlDbType = SqlDbType.Structured;
paramList.Add(tvpParam);

Here, dr is a Data Reader which contains the data read from an Excel file. The data of the excel file is as bellow:
Ref	        Amount	Date
dsasdfdsf	234.00	01/01/2014
sdfdsfdsf	567.00	01/01/2014
sdfdsfdsf	345.00	01/01/2014
sdfdsfdsf	3456.00	01/01/2014

It throws an exception when the stored procedure is executed. The exception is:
"Invalid numeric precision/scale"

I am sure that the exception is throws only because of the Date Field. Because, It works if I remove the date field from the excel file and the table valued type. I tried to use different formats of the date, even I converted the date datatype to varchar(50) in the table valued type but, it didn't work.

The problem is with the date field. Can anyone help me, please .....
Posted
Updated 27-Dec-14 21:08pm
v2

1 solution

The problem is solved by passing DataTable to the parameter instead of DataReader.
 
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