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 !!