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

  • Home
  • SEARCH
  • 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 674955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:45:51+00:00 2026-05-14T00:45:51+00:00

I am using C# and developing a winform application. I have a project class

  • 0

I am using C# and developing a winform application. I have a project class which has the project attributes.

the constructor of the project class is as follows:

newProject = new Project(GCD_ID.IsNull() ? (int?)null : Convert.ToInt32(GCD_ID), txt_Proj_Desc.Text, txt_Prop_Name.Text, ST.ID.ToString().IsNull() ? null: ST.ID.ToString(), cmbCentre.Text, 
                                     SEC.ID.ToString().IsNull() ? null : SEC.ID.ToString(), cmbZone.Text,
                                     FD.ID.ToString().IsNull() ? null : FD.ID.ToString(), DT.ID.ToString().IsNull() ? null : DT.ID.ToString(), OP.ID.ToString().IsNull() ? null : OP.ID.ToString(), T.ID.ToString().IsNull() ? null : T.ID.ToString(),
                                     CKV.ID.ToString().IsNull() ? null : CKV.ID.ToString(), STAT.ID.ToString().IsNull() ? null : STAT.ID.ToString(), MW.IsNull() ? (Double?)null : Convert.ToDouble(MW),
                                     txt_Subject.Text, Ip_Num.IsNull() ? (int?)null : Convert.ToInt32(Ip_Num), H1N_ID.IsNull() ? (int?)null : Convert.ToInt32(H1N_ID), 
                                     NOMS_Slip_Num.IsNull() ? (int?)null : Convert.ToInt32(NOMS_Slip_Num), NMS_Updated.IsNull() ? (DateTime?)null : Convert.ToDateTime(NMS_Updated),
                                     Received_Date.IsNull() ? (DateTime?)null : Convert.ToDateTime(Received_Date), Actual_IS_Date.IsNull() ? (DateTime?)null : Convert.ToDateTime(Actual_IS_Date),
                                     Scheduled_IS_Date.IsNull() ? (DateTime?)null : Convert.ToDateTime(Scheduled_IS_Date), UpSt.ID.ToString().IsNull() ? null : UpSt.ID.ToString(),
                                     UpFd.ID.ToString().IsNull() ? null : UpFd.ID.ToString(), txtHVCircuit.Text, cmbbxSIA.Text);

My problem is that i cannot insert values into the database when the datetime variables and the integer variables are null. all this data are assigned to the variable from textboxes on the form..

bELOW is the database function which takes in all the variables and insert them into the database.

public static void createNewProject(int? GCD_ID, string Project_Desc, string Proponent_Name, int Station_ID, string OpCentre, int Sector_ID, string PLZone, int Feeder, int DxTx_ID, int OpControl_ID, int Type_ID, int ConnKV_ID, int Status_ID, double? MW, string Subject, int? Ip_Num, int? H1N_ID, int? NOMS_Slip_Num, DateTime? NMS_Updated, DateTime? Received_Date, DateTime? Actual_IS_Date, DateTime? Scheduled_IS_Date, int UP_Station_ID, int UP_Feeder_ID, string @HV_Circuit, string SIA_Required)
    {
        SqlConnection conn = null;
        try
        {
            //Takes in all the employee details to be added to the database.
            conn = new SqlConnection(databaseConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("createNewProject", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("GCD_ID", GCD_ID));
            cmd.Parameters.Add(new SqlParameter("Project_Desc", MiscFunctions.Capitalize(Project_Desc)));
            cmd.Parameters.Add(new SqlParameter("Proponent_Name", MiscFunctions.Capitalize(Proponent_Name)));
            cmd.Parameters.Add(new SqlParameter("Station_ID", Station_ID));
            cmd.Parameters.Add(new SqlParameter("OpCentre", OpCentre));
            cmd.Parameters.Add(new SqlParameter("Sector_ID", Sector_ID));
            cmd.Parameters.Add(new SqlParameter("PLZone", PLZone));
            cmd.Parameters.Add(new SqlParameter("Feeder", Feeder));
            cmd.Parameters.Add(new SqlParameter("DxTx_ID", DxTx_ID));
            cmd.Parameters.Add(new SqlParameter("OpControl_ID", OpControl_ID));
            cmd.Parameters.Add(new SqlParameter("Type_ID", Type_ID));
            cmd.Parameters.Add(new SqlParameter("ConnKV_ID", ConnKV_ID));
            cmd.Parameters.Add(new SqlParameter("Status_ID", Status_ID));
            cmd.Parameters.Add(new SqlParameter("MW", MW));
            cmd.Parameters.Add(new SqlParameter("Subject", Subject));
            cmd.Parameters.Add(new SqlParameter("Ip_Num", Ip_Num));
            cmd.Parameters.Add(new SqlParameter("H1N_ID", H1N_ID));
            cmd.Parameters.Add(new SqlParameter("NOMS_Slip_Num", NOMS_Slip_Num));
            cmd.Parameters.Add(new SqlParameter("NMS_Updated", NMS_Updated));
            cmd.Parameters.Add(new SqlParameter("Received_Date", Received_Date));
            cmd.Parameters.Add(new SqlParameter("Actual_IS_Date", Actual_IS_Date));
            cmd.Parameters.Add(new SqlParameter("Scheduled_IS_Date", Scheduled_IS_Date));
            cmd.Parameters.Add(new SqlParameter("UP_Station_ID", UP_Station_ID));
            cmd.Parameters.Add(new SqlParameter("UP_Feeder_ID", UP_Feeder_ID));
            cmd.Parameters.Add(new SqlParameter("HV_Circuit", HV_Circuit));
            cmd.Parameters.Add(new SqlParameter("SIA_Required", SIA_Required));
            cmd.ExecuteNonQuery();
        }
        catch (Exception e) //returns if error incurred.
        {
            MessageBox.Show("Error occured in createNewProject" + Environment.NewLine + e.ToString());
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }

My question is, how do i insert values into the database.
please please help

  • 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-05-14T00:45:52+00:00Added an answer on May 14, 2026 at 12:45 am

    Are you getting an error saying that the parameter is missing? If so, for each of the paramaters that have a null value, use DBNull.Value instead.

    So do this, or some variation of it:

    if(H1N_ID != null)
    {
       cmd.Parameters.Add(new SqlParameter("H1N_ID",HIN_ID);
    }
    else
    {
       cmd.Parameters.Add(new SqlParameter("H1N_ID",DBNull.Value);
    }
    

    Also, anytime you are reading those fields out of the database into your objects, you should check for the DBNull.Value value and convert that to null.

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

Sidebar

Ask A Question

Stats

  • Questions 364k
  • Answers 364k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In another thread -> Call to DataSource.getConnection not returning the… May 14, 2026 at 3:33 pm
  • Editorial Team
    Editorial Team added an answer Totally impossible. In fact, proxies can't even be generated on… May 14, 2026 at 3:33 pm
  • Editorial Team
    Editorial Team added an answer 1) creates an unnamed function and executes it. this is… May 14, 2026 at 3:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.