Executing Sql Server Stored Procedure and getting OUTPUT INSERTED value

Elshan

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

Steve

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Varchar value not passing into SQL Server stored procedure

분류에서Dev

Converting Stored Procedure into a query (SQL Server Compact)?

분류에서Dev

SQL server create stored procedure syntax error

분류에서Dev

how to secure a valuable stored procedure in sql server

분류에서Dev

SQL stored procedure: how to concatenate parameter value?

분류에서Dev

Last inserted value on SQL Server with PHP

분류에서Dev

SQL Server-INSERTED.OUTPUT-변수 할당

분류에서Dev

SQL Server Merge - Output returning null deleted rows as inserted

분류에서Dev

SQL server stored procedure issue in via with c#

분류에서Dev

SQL Server : stored procedure many-to-many table query

분류에서Dev

How to pass schema as parameter to a stored procedure in sql server?

분류에서Dev

SQL Server: EXECUTE AS clause of stored procedure not granting sysadmin permissions

분류에서Dev

How to parse a VARCHAR passed to a stored procedure in SQL Server?

분류에서Dev

How can I back up a stored procedure in SQL Server?

분류에서Dev

SQL Server Stored procedure aborting when called from php

분류에서Dev

Nested stored procedure in SQL

분류에서Dev

Get ResultSet from NamedParameterJdbcTemplate executing a stored procedure

분류에서Dev

PHP with stored procedure - cursor output in Oracle

분류에서Dev

how to split a xml format data into row column format in sql server 2008 using stored procedure

분류에서Dev

SQL Server 2008 R2 - Running a Stored Procedure against Linked Servers

분류에서Dev

SQL Server CLR Library Stored Procedure static object instantiated more than once

분류에서Dev

How I do know if SQL Server Stored Procedure that performs an Update worked?

분류에서Dev

Return result set from SQL Server stored procedure to vb.net

분류에서Dev

Emailing from SQL Server stored procedure with set-based logic, avoiding cursors

분류에서Dev

Passing multiple value parameter to stored procedure

분류에서Dev

Call stored procedure from PL/SQL Job

분류에서Dev

SQL Stored Procedure Get Distinct and Update

분류에서Dev

PL/SQL Stored Procedure - IF THEN ELSE condition

분류에서Dev

SQL Stored procedure does not enter IF and CASE condition

Related 관련 기사

  1. 1

    Varchar value not passing into SQL Server stored procedure

  2. 2

    Converting Stored Procedure into a query (SQL Server Compact)?

  3. 3

    SQL server create stored procedure syntax error

  4. 4

    how to secure a valuable stored procedure in sql server

  5. 5

    SQL stored procedure: how to concatenate parameter value?

  6. 6

    Last inserted value on SQL Server with PHP

  7. 7

    SQL Server-INSERTED.OUTPUT-변수 할당

  8. 8

    SQL Server Merge - Output returning null deleted rows as inserted

  9. 9

    SQL server stored procedure issue in via with c#

  10. 10

    SQL Server : stored procedure many-to-many table query

  11. 11

    How to pass schema as parameter to a stored procedure in sql server?

  12. 12

    SQL Server: EXECUTE AS clause of stored procedure not granting sysadmin permissions

  13. 13

    How to parse a VARCHAR passed to a stored procedure in SQL Server?

  14. 14

    How can I back up a stored procedure in SQL Server?

  15. 15

    SQL Server Stored procedure aborting when called from php

  16. 16

    Nested stored procedure in SQL

  17. 17

    Get ResultSet from NamedParameterJdbcTemplate executing a stored procedure

  18. 18

    PHP with stored procedure - cursor output in Oracle

  19. 19

    how to split a xml format data into row column format in sql server 2008 using stored procedure

  20. 20

    SQL Server 2008 R2 - Running a Stored Procedure against Linked Servers

  21. 21

    SQL Server CLR Library Stored Procedure static object instantiated more than once

  22. 22

    How I do know if SQL Server Stored Procedure that performs an Update worked?

  23. 23

    Return result set from SQL Server stored procedure to vb.net

  24. 24

    Emailing from SQL Server stored procedure with set-based logic, avoiding cursors

  25. 25

    Passing multiple value parameter to stored procedure

  26. 26

    Call stored procedure from PL/SQL Job

  27. 27

    SQL Stored Procedure Get Distinct and Update

  28. 28

    PL/SQL Stored Procedure - IF THEN ELSE condition

  29. 29

    SQL Stored procedure does not enter IF and CASE condition

뜨겁다태그

보관