Epicor 10.1.400.18
What is the proper way of handling/getting the value from an EpiDateTimeEditor control in C# whether the value has been set or not?
if (MyDateEditor.Value != DBNull.Value)
if (MyDateEditor.Value.ToString() != “”)
if (MyDateEditor.Value != MyDateEditor.MinDate)
IsValidDate
.Text
My wife does not know how much time I’m spending trying to get a date.
JPS
1 Like
Dad joke Seal of Approval

4 Likes
DateTime theDate;
bool goodDate = DateTime.TryParse(MyDateEditor.Value.ToString(),theDate);
if(goodDate)
{
theDate is now usable
}
1 Like
I have a couple of unbound controls. I want to test for valid input before I update a grid. One of them is an EpiDateTimeEditor named InputScheduleDate.
Using this code:
DateTime InputSchDate;
bool ValidSchDate = DateTime.TryParse(InputScheduleDate.Value.ToString(), out InputSchDate);
Give this follow error:
Object reference not set to an instance of an object.
I isolated it to this statement:
InputScheduleDate.Value
So, I ended up with:
string strInputSchDate = "";
DateTime InputSchDate = DateTime.MinValue;
object objInputSchDate = InputScheduleDate.Value;
if (objInputSchDate != null)
{
strInputSchDate = InputScheduleDate.Value.ToString();
}
if (strInputSchDate != "")
{
InputSchDate = Convert.ToDateTime(strInputSchDate);
}
If (InputSchDate != DateTime.MinValue)
{
//do stuff
}
There must be a better way for an unbound control. Any suggestions?
Based on what you are doing, cant you just do:
DateTime InputSchDate = DateTime.MinValue;
try
{
if((DateTime)InputScheduleDate.Value >= InputSchDate)
{
do stuff
}
}
catch{}
``
I’m not sure that would work. Getting the InputScheduleDate.Value returns an object. When I try to cast the object to anything it returns the error “Object Reference not set to an instance of an object”. I believe it is because it is unbound and could have no value. I’ll try it as soon as I get back on that project though!
1 Like
I think I’ve finally settled on this:
C#
if (ShippedDate.DateTime == ShippedDate.MinDate)
{
edv.dataView[edv.Row]["Date17"] = System.DBNull.Value;
}
else
{
edv.dataView[edv.Row]["Date17"] = ShippedDate.Value;
}