Как мне присвоить значение из результирующего набора, возвращенного из процедуры insert strore?Чистый объект?
I using ado.net to do insertion to database using store procedure. After insert query , it returns two result sets using select statements. how do I get the value from return result set ?
Что я уже пробовал:
хранимая процедура:
ALTER PROCEDURE [dbo].[spInsertEmployee] ( @FirstName varchar(50), @LastName varchar(50), @Gender varchar(50), @Salary int ) AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[Employees] ([FirstName] ,[LastName] ,[Gender] ,[Salary]) VALUES (@FirstName ,@LastName ,@Gender ,@Salary) END SELECT Concat('TKT-',@FirstName,@Salary) AS TicketNumber, Concat('TKTID-',@FirstName,@LastName) as TicketID SELECT 'PASS' AS [ResultCode], 'Ticket Successfully Added' AS [ResultDetail]
using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand(spInsertEmployee, con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FirstName", model.FirstName); cmd.Parameters.AddWithValue("@LastName", model.LastName); cmd.Parameters.AddWithValue("@Gender", model.Gender); cmd.Parameters.AddWithValue("@Salary", model.Salary); //SqlParameter ticketId = new SqlParameter(); //ticketId.SqlDbType = System.Data.SqlDbType.Int; //ticketId.Direction = ParameterDirection.ReturnValue; //cmd.Parameters.Add(ticketId); con.Open(); var k = cmd.ExecuteNonQuery(); } }