"CreateDate"및 "UpdateDate"열이 포함 된 데이터 테이블이 있습니다. 가장 작은 CreateDate와 가장 큰 UpdateDate를 찾으려고합니다. 어렵지는 않지만 열에 NULL (또는 DBNull)이 포함될 수 있으며 이는 나를 트립시킵니다. 나는 다음을 사용했다 :데이터 테이블 행에서 최소/최대 datetime 찾기
DateTime dtMin = DateTime.MaxValue;
DateTime dtMax = DateTime.MinValue;
foreach(DataRow dr in dt.Rows)
{
DateTime dtCreateDate = dr.Field<DateTime>("CreateDate");
DateTime dtUpdateDate = dr.Field<DateTime>("UpdateDate");
dtMin = dtMin > dtCreateDate ? dtCreateDate : dtMin;
dtMax = dtMax > dtUpdateDate ? dtMax : dtUpdateDate;
}
내가 NULL 날짜로 행을 칠 때까지. 에만 DataRow의 값이 진행하기 전에 null의 첫 번째 경우
나는이 생각을 유효한 dtCraeteDate이고 다음 반복에서 NULL 날짜를 비교할 때 dtCreatDate를 다시 DateTime.MinValue로 설정하고 싶지 않습니다. – NoBullMan
제안 사항을 업데이트했습니다. DateTime을 선언 하시겠습니까? null 값을 포함 할 수 있습니다. – hiule