سؤال

My Model

namespace Maintenance_.Models
{
    public class ResolutionModel
    {
         public DateTime jobStart { get; set; }
    }
}

My Controller

public ActionResult Resolution()
{ 
    ActivityDetailsFacade _oActivityDetailsFacade = new ActivityDetailsFacade();
    ResolutionFacade _oResolutionFacade = new ResolutionFacade();
    DataTable act = _oActivityDetailsFacade.getActivityDetails("00704 - 4.29.2014", _oAppSetting.ConnectionString);
    foreach( DataRow temp in act.Rows)
    {
        _oResolutionModelMODEL.jobStart = Datetime.????;        <====
    }
return View();
}

I have a jobStart field in my database, and its a datetime type. Now I want my jobStart value from my database to be transfer in my model: _oResolutionModelMODEL.jobStart. How should I pass it??

هل كانت مفيدة؟

المحلول

What I have noticed you using an iteration in the foreach loop so each time you will assign the value to your model, the previous datetime will be erased. But you must have something like this:

_oResolutionModelMODEL.jobStart =(DateTime)temp["JobStart"];

But remember that if you want to store all the rows if there are many you need some changes.

نصائح أخرى

Assuming Column Name is JobStart:

_oResolutionModelMODEL.jobStart = temp["JobStart"] as DateTime;

in your loop:

foreach( DataRow temp in act.Rows)
    {
        _oResolutionModelMODEL.jobStart = temp["JobStart"] as DateTime;  <====
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top