c# - Executing Sql Server Stored Procedure and getting OUTPUT INSERTED value -
i want inserted row key when inserting records.then wrote sample sql sp.
create procedure temp begin set nocount on insert farmer_landdetails (oth_mas_key, fmr_key, anim_typ_key, anim_count, land_type_key, land_availability) output inserted.oth_det_key values(1,1,1,1,1,1) end go
how out
value c# ?
the output clause of storedprocedure returns single row single value. right method result through executescalar method of sqlcommand
using(sqlconnection cnn = new sqlconnection(....)) using(sqlcommand cmd = new sqlcommand("temp", cnn)) { cnn.open(); cmd.commandtype = commandtype.storedprocedure; int result = convert.toint32(cmd.executescalar()); }
notice have no thought datatype oth_det_key
. assume integer hence convert.toint32() on homecoming value of executescalar
c# sql-server
No comments:
Post a Comment