title: Is it possible to insert null(" ") value to the datetime field in the database
body: <p>I have two fields DOB(date of birth) and (date of joining) If user enter the date then in the database
   insert->date else insert->null</p>
  
  <p>I have define <strong>properties</strong> as</p>
  
  <pre><code>  public DateTime DOB
      {
          get;
          set;
      }
      public DateTime DOJ
      {
          get;
          set;
      }
  </code></pre>
  
  <p>Now in save_click event</p>
  
  <pre><code>        IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
          String datetime = txtDOB.Text.Trim();
          DateTime date = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
          objEmp.DOB = date;
  
          provider = new System.Globalization.CultureInfo("en-CA", true);
          datetime = txtDOJ.Text.Trim();
          date = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
          objEmp.DOJ = date;
  </code></pre>
  
  <p><strong>class.cs</strong></p>
  
  <pre><code>        param[7] = new Service.SqlParameter();
          param[7].ParameterName = "@DOB";
          param[7].Value = DOB;
          param[7].SqlDbType = Service.SqlDbType.DateTime;
  
          param[8] = new Service.SqlParameter();
          param[8].ParameterName = "@DOJ";
          param[8].Value = DOJ;
          param[8].SqlDbType = Service.SqlDbType.DateTime;
  </code></pre>
  
  <p>I want that when user did not insert any date then null should be inserted... But by this code i am getting an error
  <strong>Store procedure</strong></p>
  
  <pre><code>@FK_EmployeeTypeID Numeric(18,0),
      @EmployeeName NVARCHAR(50), 
      @CellNo  NVARCHAR(50),  
      @PhNo  NVARCHAR(50),    
      @Address  NVARCHAR(Max),    
      @Email  NVARCHAR(50),   
      @DOB DATETIME,
      @DOJ DATETIME,
      @DOR NVARCHAR(12),
      @Status NVARCHAR(50),
      @Remarks NVARCHAR(Max)
  
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      -- Insert statements for procedure here
      BEGIN TRY
          BEGIN TRANSACTION Employee_Insert
      INSERT 
      INTO
      Employee
      (
          FK_EmployeeTypeID,
          EmployeeName,   
          CellNo, 
          PhNo,   
          Address,    
          Email,  
          DOB,
          DOJ,
          DOR,
          Status,
          Remarks
  
      )
      VALUES
      (
  
          @FK_EmployeeTypeID,
          @EmployeeName,  
          @CellNo,    
          @PhNo,  
          @Address,   
          @Email, 
          @DOB,
          @DOJ,
          @DOR,
          @Status,
          @Remarks
      )
  
          COMMIT TRANSACTION Employee_Insert
      SELECT '1'
      END TRY
      BEGIN CATCH
          SELECT 'Error : ' + ERROR_MESSAGE()
          ROLLBACK TRANSACTION Employee_Insert
      END CATCH
  </code></pre>
  
  <p><strong>Webservice</strong></p>
  
  <pre><code>[WebMethod]
      public string InsUpdDel(string Conn, string ProcName, SqlParameter[] p)
      {
          try
          {
              using (SqlConnection cn = new SqlConnection(Conn))
              {
                  if (cn.State == ConnectionState.Open || cn.State == ConnectionState.Broken || cn.State == ConnectionState.Connecting || cn.State == ConnectionState.Executing || cn.State == ConnectionState.Fetching)
                      cn.Close();
                  cn.Open();
                  SqlCommand cmd = new SqlCommand(ProcName, cn);
  
                  cmd.CommandType = CommandType.StoredProcedure;
  
                  foreach (SqlParameter param in p)
                  {
                      cmd.Parameters.Add(param);
                  }
                  SqlDataReader dr = cmd.ExecuteReader();
                  dr.Read();
                  if (dr[0].ToString() == "1")
                  {
                      return "1";
                  }
                  else
                  {
                      return dr[0].ToString();
                  }
                  dr.Close();
                  cn.Close();
              }
          }
          catch (Exception ex)
          {
              return "Error : " + ex.Message.ToString();
          }
  </code></pre>