Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot unbox as Int

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
like image 867
CSharper Avatar asked Feb 16 '23 16:02

CSharper


1 Answers

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#.

like image 162
Pramod Mangalore Avatar answered Feb 22 '23 19:02

Pramod Mangalore