Return Maximum Inserted ID from Stored Procedure and display in Label using C# .Net

Last Reply on Mar 17, 2015 12:49 AM By Shubh4m

Posted on Mar 16, 2015 04:21 AM

how to bind maxid from table in Label using storedprocedure...

You are viewing reply posted by: Shubh4m on Mar 17, 2015 12:49 AM.
Posted on Mar 17, 2015 12:49 AM

Stored Procedure:

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE MaxId

     

AS

BEGIN

      SET NOCOUNT ON;

      SELECT Max(Id) From YOURTABLENAME

END

GO

 

C#:

public void docNo()
    {
        con.Open();
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "MaxId";
        var x= cmd.ExecuteScalar();
        
        LBLy.Text = (string)x;
        //LBLy.Text = yy;
        
        con.Close();
    }

 

Hope this might help !!