i am fetching the date by below code from db using c# ,how to check null date .when date is null then it shows default date on page 01/01/0001
IssueDate = dataReader.GetValue<DateTime>(DbColumnNames.PLAST_ISSUE_DT)
i am fetching the date by below code from db using c# ,how to check null date .when date is null then it shows default date on page 01/01/0001
IssueDate = dataReader.GetValue<DateTime>(DbColumnNames.PLAST_ISSUE_DT)
DateTime is not a refence type, so it cannot be null. You can use a nullable date with DateTime? (which is the same as Nullable<DateTime>) to check for null value.
DateTime? issueDate = dataReader.GetValue<DateTime?>(DbColumnNames.PLAST_ISSUE_DT);
if (issueDate == null) {
// Is null
}
Or check for the default value of DateTime, which should be 01/01/0001.
DateTime issueDate = dataReader.GetValue<DateTime>(DbColumnNames.PLAST_ISSUE_DT);
if (issueDate == default) {
// Is default value
}
DateTime is a value type so it always evaluates to something. Likewise, if you don't put a value in an int the value inside will be 0 and not null.
If you do want to have null then you have to make your database field nullable and use a define IssueDate as type DateTime? which is Nullable of DateTime and it will be able to hold the null value.