Example #1
0
        public List <DistrictData> GetLQASData()
        {
            List <DistrictData> list = new List <DistrictData>();
            SqlConnection       con  = new SqlConnection(WebConfigurationManager.ConnectionStrings["DTA"].ConnectionString);//connectionString

            con.Open();

            using (con)
            {
                using (var command = con.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM Coverage_district";

                    using (var reader = command.ExecuteReader())
                    {
                        var indexOfCol1  = reader.GetOrdinal("Id");
                        var indexOfCol2  = reader.GetOrdinal("Region");
                        var indexOfCol3  = reader.GetOrdinal("Year");
                        var indexOfCol4  = reader.GetOrdinal("Round");
                        var indexOfCol5  = reader.GetOrdinal("TypeOfCampaign");
                        var indexOfCol6  = reader.GetOrdinal("TargetPop");
                        var indexOfCol7  = reader.GetOrdinal("PercVacCoverage");
                        var indexOfCol8  = reader.GetOrdinal("MissedChildren");
                        var indexOfCol9  = reader.GetOrdinal("PercRecovDay1");
                        var indexOfCol10 = reader.GetOrdinal("PercRecovDay2");
                        var indexOfCol11 = reader.GetOrdinal("PercRecovDay3");

                        var indexOfCol13 = reader.GetOrdinal("PercRecovDay5");
                        var indexOfCol14 = reader.GetOrdinal("PercNSSRecovered");
                        var indexOfCol15 = reader.GetOrdinal("Location");
                        var indexOfCol16 = reader.GetOrdinal("ParentId");
                        var indexOfCol17 = reader.GetOrdinal("Province");

                        while (reader.Read())
                        {
                            DistrictData obj = new DistrictData();
                            obj.Id              = Convert.ToInt32(reader.GetValue(indexOfCol1));
                            obj.Region          = reader.GetValue(indexOfCol2).ToString();
                            obj.Year            = Convert.ToInt32(reader.GetValue(indexOfCol3));
                            obj.Round           = reader.GetValue(indexOfCol4).ToString();
                            obj.TypeOfCampaign  = reader.GetValue(indexOfCol5).ToString();
                            obj.TargetPop       = Convert.ToInt64(reader.GetValue(indexOfCol6));
                            obj.PercVacCoverage = Convert.ToDouble(reader.GetValue(indexOfCol7));
                            obj.MissedChildren  = Convert.ToInt64(reader.GetValue(indexOfCol8));
                            obj.PercRecovDay1   = Convert.ToDouble(reader.GetValue(indexOfCol9));
                            obj.PercRecovDay2   = Convert.ToDouble(reader.GetValue(indexOfCol10));
                            obj.PercRecovDay3   = Convert.ToDouble(reader.GetValue(indexOfCol11));

                            obj.PercRecovDay5    = Convert.ToDouble(reader.GetValue(indexOfCol13));
                            obj.PercNSSRecovered = Convert.ToDouble(reader.GetValue(indexOfCol14));
                            obj.Location         = reader.GetValue(indexOfCol15).ToString();
                            obj.ParentId         = reader.GetValue(indexOfCol16).ToString();
                            obj.Province         = reader.GetValue(indexOfCol17).ToString();
                            //Need to read value from correct column index
                            obj.ParentId = (reader.GetValue(indexOfCol16).ToString() == "") ? null : reader.GetValue(indexOfCol16).ToString();
                            list.Add(obj);
                        }
                        reader.Close();
                    }
                }
                con.Close();
            }
            return(list);
        }