c# - How to know the identity value to use in another stored procedure, Inserting from a windows form -


i need use identity value of inserted record, insert in table. insertions done using stored procedures, called winforms button event. procedures parameterised, can't execute first procedure in procedure

procedure [dbo].[insert_trans] (   @name nvarchar(50),   @email nvarchar(50),   @ata_certification bit,   @st1 nvarchar(50),   @st2 nvarchar(50),   @city nvarchar(max),   @state nvarchar(max),   @country nvarchar(max),   @zipcode numeric(18, 0),   @qualification nvarchar(50),   @interpreting_service bit ,   @tran_int_degree bit,   @total_experience int,   @native_language nvarchar(50),   @resume bit ) begin     insert location_master (         st1,         st2,          city,          state,          country,          zipcode     ) values (         @st1,         @st2,         @city,         @state,         @country,         @zipcode)      declare @location_id int     set @location_id = (select cast(scope_identity() varchar(10))                         last_identity)      insert translators values (         @name,          @email,         @ata_certification,         @location_id,                      @qualification,          @interpreting_service,         @tran_int_degree,                      @total_experience,          @native_language,          @resume)  end 

and second procedure, require sno generated

procedure insert_langknown (     @translator_id int,     @language_code varchar(50) ) begin      insert language_known (         translator_id,         language_code     ) values (         @translator_id,         @language_code) end 

the translator id required field

you can return value store procedure below

select scope_identity() 

and can access return value in vb.net code below

command.executescalar() 

otherwise directly send inserted value record procedure as

declare @returnval int select @returnval=scope_identity()  exec another_procedure @returnval,another_parameter   -- 'another_procedure' storepd procedure name 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -