Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 545.2k

Count No of Records returned

Jun 21 2021 4:05 AM

Hi

   I have below class & in Controller i want to get no of rows returned.

public Location GetById(string Id)
        {
            Location objLocation = new Location();
            try
            {
                using (SqlConnection con = new SqlConnection(Common.Con))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("sp_Location", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", Id);
                    cmd.Parameters.AddWithValue("@Action", "L");
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        objLocation.Id = rdr["Id"].ToString();
                        objLocation.Description = rdr["Description"].ToString();
                        objLocation.GstStateCode = rdr["GstStateCode"].ToString();
                        objLocation.GstStateName = rdr["GstStateName"].ToString();
                        objLocation.GstNo = rdr["GstNo"].ToString();
                        objLocation.IsActive = Convert.ToBoolean(rdr["IsActive"]);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogging.SendExcepToDB(ex);
                return -1;
            }
            return objLocation;
        }

Thanks


Answers (3)