c# - Comparing DateTime variable to DateTime data type column with Null values in it -


i have c# search on records in array sql server db using 3 data elements. 1 of data elements has datetime element in column called dateofbirth. unfortunately there lot of null values in column , can't figure out how compare datetime variable field null values. see lot of answers appear close need here, nothing has helped. help, has been format.

if ((datetime)dt == (datetime)temp[i].individual.dateofbirth)     globalnum3.bnum3 = 1; 

i'm assuming dt datetime, in case can't null (datetime struct) , there's no need cast it.in addition, either temp[i].individual.dateofbirth datetime , cannot null either, or it's nullable<datetime>.

assuming both datetimes, db nulls set datetime.minvalue, compare values:

if (dt == (datetime)temp[i].individual.dateofbirth) {     globalnum3.bnum3 = 1; } 

however, if temp[i].individual.dateofbirth nullable<datetime>, might null, or might have no value, use this:

var possibledateofbirth = temp[i].individual.dateofbirth; if (possibledateofbirth != null &&     possibledateofbirth.hasvalue &&     dt == possibledateofbirth.value) {     globalnum3.bnum3 = 1; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -