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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:55:29+00:00 2026-05-23T10:55:29+00:00

My code works fine as far as I give the values for Begin date

  • 0

My code works fine as far as I give the values for Begin date and enddate. However, when they are null values, it returns the format exception. This is what I did:

public static string CheckInsertRecord(String EventType, String BeginDate, String EndDate) 
{
    NCDCPoint ncdc = new NCDCPoint();
    CEOSurveyDataContext CDC = new CEOSurveyDataContext();
    int et = Convert.ToInt32(EventType);
    CultureInfo provider = CultureInfo.InvariantCulture;
    DateTime b = Convert.ToDateTime(BeginDate);
    DateTime e = Convert.ToDateTime(EndDate);

    var query = (from n in CDC.NCDCPoints
                where n.EVENT_TYPE_ID == et && n.BeginDate == b && n.EndDate == e
                select new { 
                   n.EVENT_TYPE_ID,
                   BeginDate =  n.BeginDate.ToString("yyyy-MM-dd",provider),
                   EndDate = n.EndDate.ToString(),
                   n.BeginLATLONG,
                   n.EndLATLONG
                });
   if (query.Any())
   {
       return new JavaScriptSerializer().Serialize(query.ToList());
   }
   else
   {
       return "No duplicate";
   }
}

Putting try and catch was not useful as I cannot access the return values. Can u please let me know how to deal with this error.

  • 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-23T10:55:29+00:00Added an answer on May 23, 2026 at 10:55 am

    DateTime is not nullable. So trying to format a string that is Null or Empty should return an exception.

    public static string CheckInsertRecord(String eventType, String beginDate, String endDate)
    {
        NCDCPoint ncdc = new NCDCPoint();
        CEOSurveyDataContext CDC = new CEOSurveyDataContext();
        int et = Convert.ToInt32(eventType);
        CultureInfo provider = CultureInfo.InvariantCulture;
    
        String queryBeingDate = string.Empty;
        String queryEndDate = string.Empty;
        DateTime beginDateTime;
        DateTime endDateTime;
        if (DateTime.TryParse(beginDate, out beginDateTime))
        {
           queryBeingDate = beginDateTime.ToString("yyyy-MM-dd");
        }
    
        if(DateTime.TryParse(endDate, out endDateTime))
        {
           queryEndDate = endDate;
        }
    
        var query = (from n in CDC.NCDCPoints
                     where n.EVENT_TYPE_ID == et && n.BeginDate == b && n.EndDate == e
                     select new
                     {
                         n.EVENT_TYPE_ID,
                         BeginDate = queryBeingDate,
                         EndDate = queryEndDate,
                         n.BeginLATLONG,
                         n.EndLATLONG
                     });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works fine to find an available room within certain date, but it
The following code works fine for Visual C++ 2008. However, when comes to Visual
The following code works fine so far. But now I want to map the
So far my networking code works fine, but I'm a bit worried about something
I'm trying to create an android keyboard, this code works fine so far package
This code works fine: $result = $client->__call(optionalInfo, array( new SoapParam(..., client), new SoapParam(..., add_code))
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
My below code works fine and is used to populate a <select> item with

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.