title: How to handle the null value in asp.net using Datetime?
body: <p>this is my code to save the student record,</p>
  
  <pre><code>int x = clsFunctions.InsertStudent(txtStudent.Text,Convert.ToDateTime(txtContractDate.Text))
  </code></pre>
  
  <p>and the function definition is,</p>
  
  <pre><code>public static int InsertStudent(string Name, DateTime ContractDate)
  {
  int isaved = 0;
  SqlParameter[] sqlprm = new SqlParameter[2];
  
  sqlprm[0] = new SqlParameter("@Name", SqlDbType.VarChar, 100);
  sqlprm[0].Value = Name;
  
  sqlprm[1] = new SqlParameter("@ContractDate", SqlDbType.Date);
  sqlprm[1].Value = ContractDate;
  
  isaved = db.ExecuteNonQueryProcedure("ProcedureName", sqlprm);
  return isaved;
  }
  </code></pre>
  
  <p>db.ExecuteNonQueryProcedure is the function to call ExecuteNonQuery()...</p>
  
  <p>My question is that when I enter the value in ContractDate field, it works fine, the data is saved in database.. But when I left it empty, I got an error "String was not recognized as a valid DateTime". The ContractDate field in a table in database is 'Allow null'. How to handle this null value through this code as ContractDate field is not mandatory on the form ?</p>