Question

Controller

foreach (DataRow temp in act.Rows)
{
    _oResolutionModel.activityNo = temp["ActivityID"].ToString();
    _oResolutionModel.assignTechnician = temp["TechNo"].ToString();
    _oResolutionModel.recommendation = temp["RECOMMENDATION"].ToString();
    _oResolutionModel.jobStart = (DateTime)temp["JobStart"];
    _oResolutionModel.jobEnd = (DateTime)temp["JobEnd"];
        _oResolutionFacade.setResolutionID(_oResolutionModel.activityNo);
        DataTable res = _oResolutionFacade.getResolution(_oAppSetting.ConnectionString);
        foreach (DataRow x in res.Rows)
        {
            _oResolutionModel.solution = x["Resolution"].ToString();
            _oResolutionModel.remarks = x["Remarks"].ToString();
            _oResolutionList.Add(_oResolutionModel);
            break;
        }
    _oResolutionList.Add(_oResolutionModel);
    break;
}

In here my _oResolutionList count = 1, meaning there's two data in it and it duplicated the first data. I want to have only 1 data in my _oResolutionList. Do I need to add some code in my inner Foreach or should I change something on it.?

Or You can suggest me how to delete the second data entry.?

Was it helpful?

Solution

Instead of using a foreach loop. You can also check the nullity first and then assign. You can also do :

  _oResolutionFacade.setResolutionID(_oResolutionModel.activityNo);
    DataTable res = _oResolutionFacade.getResolution(_oAppSetting.ConnectionString);
     _oResolutionModel.solution = res.Rows[0]["Resolution"].ToString() ?? string.Empty; //To make sure that if it is null it will assign to an empty string
     _oResolutionModel.remarks = res.Rows[0]["Remarks"].ToString()?? string.Empty;

You have many solutions to deal with that. Hope it will help you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top