Cannot unbox as Int

c#, parameters, unboxing

Solution

I had the same issue.

The INT being returned in stored procedure is of type 'SHORT'. I do not know why.

Cannot cast ..."@SubjectID"... (which has an actual type of 'short') to 'string'.

Solution: 1. Unbox to 'SHORT' in c# OR 2. Use Convert.ToInt32 in c#.

Problem

I have this sql parameter im getting the cant unbox as int error ``` returnValue = (int)cmdUpdateCreatedOn.Parameters["@intcount"].Value; ``` return value is declared as int returnValue = 0 and my parameter is also declared as int, and it is getting the rowcount of rows updated. I've tried different converting syntax none seem to work. MY SP is ``` ALTER Procedure [dbo].[UpdateStation] @intcount int output AS select StationaryName into #stname from Stationaries where Authorized = 0 select * from #stname Update Stationaries Set Authorized = 1 where Authorized = 0 set @intcount = @@rowcount ```

Original source

Related problems