Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:35:51+00:00 2026-06-12T20:35:51+00:00

I have a Class like this public class MyClass { public int Id {

  • 0

I have a Class like this

public class MyClass
{
    public int Id { get; set; }
    public Nullable<DateTime> ApplicationDate { get; set; }
    ....
}

Now I’m trying to fill an object of MyClass like this

DataTable dt = DBHelper.GetDataTable(sql, conn);
DataRow dr = dt.Rows[0];

MyClass oMyClass = new MyClass();
oMyClass.Id = (int)dr["Id"];
oMyClass.ApplicationDate = dr["ApplDate"] == DBNull.Value ? null : Convert.ToDateTime(dr["AppDate"]); 
//Above line gives an error
....

Assigning of Application Date value gives an error

Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'System.DateTime'

What am I missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:35:53+00:00Added an answer on June 12, 2026 at 8:35 pm

    You need to cast null to DateTime?:

    oMyClass.ApplicationDate = dr["ApplDate"] == DBNull.Value 
        ? (DateTime?)null 
        : Convert.ToDateTime(dr["AppDate"]); 
    

    This is because of the way the compiler determines the resulting type of the conditional operator; the behavior is by design:

    Either the type of first_expression and second_expression must be the
    same, or an implicit conversion must exist from one type to the other.

    Since null by itself is of null type and thus there is no conversion from or to it, you need to help the compiler by casting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object model like this: public class MyClass { int TheProp {get;set;}
I have something like this: class SomeClass { public int Id {get;set} public int
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
I have a class: public class MyClass { public int code { set; get;
Given this class: public class MyClass { public int MyProperty {get; set;} } How
I have a class with two constructors that look like this: public MyClass(SomeOtherClass source)
Currently I have a class that looks like this: public class MyClass : IMyClass
So I have a model like this: class MyClass { public $customer = null;
I have a List<MyClass> The class is like this: private class MyClass { public
Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.