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 643581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:17:55+00:00 2026-05-13T21:17:55+00:00

I have a class named project with the following data members. class Project {

  • 0

I have a class named project with the following data members.

class Project
{
    private int Record_Num;
    private int GCD_ID;
    private string Project_Desc;
    private string Proponent_Name;
    private string Station_ID;
    private string OpCentre;
    private string Sector_ID;
    private string PLZone;
    private string Feeder_ID;
    private string DxTx_ID;
    private string OpControl_ID;
    private string Type_ID;
    private string ConnKV_ID;
    private string Status_ID;
    private double MW;
    private string Subject;
    private int Ip_Num;
    private int H1N_ID;
    private int NOMS_Slip_Num;
    private DateTime NMS_Updated;
    private DateTime Received_Date;
    private Nullable<DateTime> Actual_IS_Date;
    private string Scheduled_IS_Date;
    private string UP_Station_ID;
    private string UP_Feeder_ID;
    private string HV_Circuit;
}

i query the database and retrieve the values through a data table which assigns the value to the project object like this.

for (int prjIdx = 0; prjIdx < dt.Rows.Count; prjIdx++)
            {
                newProject = new Project(Convert.ToInt32(dt.Rows[prjIdx]["RecordNum"].ToString()), Convert.ToInt32(dt.Rows[prjIdx]["GCDID"].ToString()),
                    dt.Rows[prjIdx]["ProjectDesc"].ToString(), dt.Rows[prjIdx]["ProponentName"].ToString(),
                    dt.Rows[prjIdx]["StationName"].ToString(), dt.Rows[prjIdx]["OpCentre"].ToString(),
                    dt.Rows[prjIdx]["SectorName"].ToString(), dt.Rows[prjIdx]["PLZone"].ToString(),
                    dt.Rows[prjIdx]["FeederDesc"].ToString(), dt.Rows[prjIdx]["DxTx"].ToString(),
                    dt.Rows[prjIdx]["OpControl"].ToString(), dt.Rows[prjIdx]["Type"].ToString(),
                    dt.Rows[prjIdx]["ConnectionKV"].ToString(), dt.Rows[prjIdx]["Status"].ToString(),
                    Convert.ToDouble(dt.Rows[prjIdx]["MW"]), dt.Rows[prjIdx]["Subject"].ToString(),
                    Convert.ToInt32(dt.Rows[prjIdx]["IpNum"]), Convert.ToInt32(dt.Rows[prjIdx]["H1NID"]),
                    Convert.ToInt32(dt.Rows[prjIdx]["NomsSlipNum"]),Convert.ToDateTime(dt.Rows[prjIdx]["NmsUpdated"]),
                    Convert.ToDateTime(dt.Rows[prjIdx]["ReceivedDate"]),Convert.ToDateTime(dt.Rows[prjIdx]["ActualIsDate"]),
                    dt.Rows[prjIdx]["ScheduledIsDate"].ToString(),dt.Rows[prjIdx]["UpStation"].ToString(),dt.Rows[prjIdx]["UpFeeder"].ToString(),
                    dt.Rows[prjIdx]["HVCircuit"].ToString());

                newProject.record_num = Convert.ToInt32(dt.Rows[prjIdx]["RecordNum"]);
                projList.Add(newProject);

            }

now my problem is, all the date time values retrieved from the database can be null.so if it encounters a null value, it fails to convert it and hence it cannot be assigned in to the object. thus it give me an error

how do i tackle the proble.
should i change the date time variable to string data type. but thats a lame solution. please help//

  • 1 1 Answer
  • 1 View
  • 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-05-13T21:17:55+00:00Added an answer on May 13, 2026 at 9:17 pm

    DateTime is a value-type, you could use the nullable datetime (DateTime?)

    MSDN Ref on Nullable Structure

    [...]
    private int NOMS_Slip_Num;
    private DateTime? NMS_Updated;
    private DateTime? Received_Date;
    private Nullable<DateTime> Actual_IS_Date;
    [...]
    

    Doing so will require changes in how you retrieve the value. One way to do so, would be to implement a null or DBNull check, and set the value of nullable datetimes in the Project instanciation using a ternary operator.

    public static class Extensions
    {
        public static bool IsNull(this object o)
        {
            if (o == null || DBNull.Value.Equals(o))
                return true;
            else
                return false;
        }
    }
    

    and use it like this in Project’s instanciation :

    var receivedDate = dt.Rows[prjIdx]["ReceivedDate"];
    var actualDate = dt.Rows[prjIdx]["ActualIsDate"];
    newProject = new Project([...],
                           receivedDate.IsNull() ? null : Convert.ToDateTime(receivedDate),
                           actualDate.IsNull() ? null : Convert.ToDateTime(actualDate),
                           [...]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Project model: public class Project { [Key] public int ProjectID
In my project, I have a wrapper class named PlayerCluster.java , which loads the
Here's an odd one. I have a class named TileMap with the following interface:
Suppose i have class Person { public int Id {get;set;} public string Name {get;set;}
In my solution I have 4 projects named UI,Business,Data and common.In the Data project
I have the following solution structure: Portal.DataAccess -> Class library project with methods against
Need to add two same name .csproj class libraries in my solution.Have two project
I have a Project model similar to: class Project(models.Model): ... lead_analyst=models.ForeignKey(User, related_name='lead_analyst') ... I
i have class named Group i tried to test configuration: var cfg = new
I have a class named CropImageView which is extended from ImageView . but the

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.