I have a TextBox control that holds a date, that often could be null. I'm using it in an Insert and when I try to insert I'm getting the error message:
String was not recognized as a valid DateTime.
I'm unsure how to pass the null value as a datetime. Here is my code.
It's Convert.ToDateTime(txtDateAction.Text) that I'm having problems with.
protected void btnLog_Click(object sender, EventArgs e)
{
PhoneLogsBLL.InsertOCASPhoneCall(
Convert.ToInt16(txtStaffID.Text),
Convert.ToDateTime(txtDate.Text),
chkAdvisoryBoard.Checked,
chkClaims.Checked,
chkDR.Checked,
chkEEOICPA.Checked,
chkOCAS.Checked,
chkPhysicianPanel.Checked,
chkPC.Checked,
chkWebsite.Checked,
chkSEC.Checked,
chkCATI.Checked,
chkNIOSH800.Checked,
chkORAU800.Checked,
chkCongressional.Checked,
chkCOI.Checked,
chkDOLOutreach.Checked,
txtDiscussion.Text,
chkActionRequired.Checked,
Convert.ToDateTime(txtDateAction.Text),
txtAction.Text,
0,
chkActivityReport.Checked);
}
public static void InsertOCASPhoneCall(
short sintStaffID,
DateTime dtmDateCalled,
bool blnAB,
bool blnClaims,
bool blnDR,
bool blnEEOICPA,
bool blnOCAS,
bool blnPhysicianPanel,
bool blnPC,
bool blnWebSite,
bool blnSEC,
bool blnCATI,
bool blnNIOSH800,
bool blnORAU800,
bool blnCC,
bool blnCOI,
bool blnDOL,
string vcharDiscussion,
bool blnActionNeeded,
DateTime dtmActionTaken,
string ActionTaken,
short sintActionTakenStaffID,
bool blnActivityReport)
{
UnitOfWorkCTS uow = new UnitOfWorkCTS();
using (var repo = new OCASPhoneCallsRepository(uow))
{
OCASPhoneCalls call = new OCASPhoneCalls();
call.dtmDateCalled = dtmDateCalled;
call.sintStaffID = sintStaffID;
call.blnAB = blnAB;
call.blnClaims = blnClaims;
call.blnDR = blnDR;
call.blnEEOICPA = blnEEOICPA;
call.blnOCAS = blnOCAS;
call.blnPhysicianPanel = blnPhysicianPanel;
call.blnPC = blnPC;
call.blnWebSite = blnWebSite;
call.blnSEC = blnSEC;
call.blnCATI = blnCATI;
call.blnNIOSH800 = blnNIOSH800;
call.blnORAU800 = blnORAU800;
call.blnCC = blnCC;
call.blnCOI = blnCOI;
call.blnDOL = blnDOL;
call.vcharDiscussion = vcharDiscussion;
call.blnActionNeeded = blnActionNeeded;
call.dtmActionTaken = dtmActionTaken;
call.sintActionTakenStaffID = sintActionTakenStaffID;
call.blnActivityReport = blnActivityReport;
repo.InsertOrUpdate(call);
uow.Save();
}
}