c# - Unable to read value returned from a stored procedure using Entity Framework -


i have written stored procedure return me id of row if found , if not found, create row , return id of newly created row. facing problems in retrieving returned value in c# function.


the stored procedure:

procedure [tagdatabase].[gettagid]      -- add parameters stored procedure here     @tagname varchar(200),      @userid int = 0,     @tagid int = 0 output begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;     select @tagid=id tag name = @tagname , userid=@userid;     if nullif(@tagid, '') null     begin         declare @outputtbl table (id int)          insert tag(name, parentid, userid)         output inserted.id @outputtbl(id)         values (@tagname, 0, @userid);          select @tagid=id @outputtbl       end      select @tagid end 

my function retrieve value returned this:

objectparameter objparam = new objectparameter("tagid", typeof(long));  context.gettagid("newtag", 10, objparam); context.savechanges(); long id = convert.toint64(convert.toint64(id))); 

change

long id = convert.toint64(convert.toint64(id)));

to

long id = convert.toint64(objparam.value);


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -