Link to home
Start Free TrialLog in
Avatar of enrique_aeo
enrique_aeo

asked on

retrieve the identity value in my data layer

hi expert, i have this store procedure
create procedure [dbo].[EvaluacionSentenciasJudicialesInsertar]
(
  @tipoDocumento char(1) ,
      @numeroDocumento varchar(50) ,
...
)
AS
SET NOCOUNT ON
INSERT INTO [EvaluacionSJ].[dbo].[EvaluacionSentenciasJudiciales]
           ([tipoDocumento]
           ,[numeroDocumento]
   ...
     
     VALUES
           (
                                    @tipoDocumento
           ,@numeroDocumento
           ...
           )
           
select @@IDENTITY

as I can do to get this code (@ @ identity) in my data layer. net?

this i my code in .net
protected void btnSave_Click(object sender, EventArgs e)
    {
        con = new SqlConnection(ObtenerConexion());

        cmd = new SqlCommand("EvaluacionSentenciasJudicialesInsertar", con);

        cmd.Parameters.Add("@tipoDocumento", SqlDbType.Char).Value = ddlTipoDocumento.SelectedItem.Value;
        cmd.Parameters.Add("@numeroDocumento", SqlDbType.VarChar).Value = txtNumeroDocumento.Text.Trim();
        cmd.Parameters.Add("@condicionMagistrado", SqlDbType.Char).Value = ddlCondicionMagistrado.SelectedItem.Value;
        cmd.Parameters.Add("@obsManejoJurisprudencial", SqlDbType.VarChar).Value = txtManejoJurisprudencial.Text.Trim();

        cmd.CommandType = CommandType.StoredProcedure;

        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            LimpiarControles();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
        }

     }
Avatar of puru1981
puru1981

in this case you need to use executereader.

alternatively, make an output parameter and set the value of output parameter in SP and retrieve the same in your C# code.
Avatar of enrique_aeo

ASKER

can you give the code to:
 make an output parameter and set the value of output parameter in SP and retrieve the same in your C# code
ASKER CERTIFIED SOLUTION
Avatar of puru1981
puru1981

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and how to retrieve the value to assign to a text box?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial