I want to get inserted row key when inserting records.Then I wrote this Sample SQL SP.
CREATE PROCEDURE Temp
AS
BEGIN
SET NOCOUNT ON
insert into 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 to get this OUT
value with C# ?
The Output clause of your StoredProcedure returns a single row with a single value.
So the correct method to get its result is through the ExecuteScalar method of an 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 that I have no idea what datatype is oth_det_key
. I assume an integer hence the Convert.ToInt32() on the return value of ExecuteScalar
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다