internal static CConsignments getInstance(string ConsignmentNo, bool Billed) { object ObjVal; CConsignments cTemp; PropertyInfo[] arrPi; DataTable DT = new DataTable(); try { cTemp = new CConsignments(); DT = getAllData(ConsignmentNo, Billed); if (DT.Rows.Count > 0) { arrPi = cTemp.GetType().GetProperties().First(x => x.Name == "GridProperties").GetValue(cTemp) as PropertyInfo[]; DT.Columns["TravelFrom"].ColumnName = "TravelFromID"; DT.Columns["TravelTo"].ColumnName = "TravelToID"; foreach (PropertyInfo pi in arrPi) { if (!DT.Rows[0].IsNull(pi.Name)) { ObjVal = DT.Rows[0][pi.Name]; pi.SetValue(cTemp, ObjVal); } } ObjVal = null; } else { cTemp.strError = "No consignment data found"; } return(cTemp); } catch (Exception ex) { cTemp = new CConsignments() { strError = ex.Message }; return(cTemp); } finally { DT = null; ObjVal = null; cTemp = null; arrPi = null; } }