1
我想從SQL數據庫獲取datetime並將其存儲在DateTime屬性中。 目前它的值爲null。 我不斷收到轉換錯誤。使用MVVM在C#中編程。來自SQL數據庫的值爲null的DateTime
private void LoadFunctie()
{
_myModel = new ObservableCollection<myModel>();
DataTable DT = new DataTable();
DT =
clsDAC.ExecuteDataTable(Properties.Resources.S_myStoredProcedure);
foreach (DataRow DR in DT.Rows)
{
var x = new clsOrderOverzichtM()
{
SomeID = (int)DR[0],//works
SomeString = DR[1].ToString(),//works
SomeDate = (DateTime)DR[2]//ERROR
};
_myModel.Add(x);
}
}
我的房屋
private DateTime? _SomeDate;
public DateTime? SomeDate
{
get { return _SomeDate; }
set
{
_SomeDate = value;
RaisePropertyChanged();
}
}
什麼可能是我的問題嗎?
TY!它終於有效! :) –