Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 516.6k

Max Value Retreive Code

Sep 2 2024 4:16 AM

Hi

  In below code i am getting Column Max Value from a table. I want that at same time 2 User should not be able to access same value

using (SqlConnection con0 = new SqlConnection(Common.CommonFunction.cnn_Live))
{
    SqlCommand cmd0 = new SqlCommand("sp_MaxDocEntry", con);
    cmd0.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.AddWithValue("@TableName", SqlDbType.VarChar).Value = "Department";
    SqlParameter successParam1 = cmd.Parameters.Add("@Success", SqlDbType.Bit);
    successParam1.Direction = ParameterDirection.Output;
    SqlParameter DocEntry = cmd.Parameters.Add("@DocEntry", SqlDbType.Int);
    DocEntry.Direction = ParameterDirection.Output;
    con.Open();

    cmd.ExecuteNonQuery();
    bool success1 = (bool)successParam1.Value;
    if (success1)
    {
        cmd.Parameters.AddWithValue("@DocEntry", SqlDbType.Int).Value = successParam0;
        int MaxDocEntry = Convert.ToInt32(DocEntry.Value);
    }
    else
    {
        ShowMessage("", success1.ToString(), "error");
    }
}

Thanks


Answers (5)