Return nullable datetime from scalar, stored procedure
- by molgan
Hello
I have a function that returns a date from a stored procedure, and it all works great til the value is NULL, how can I fix this so it works with null aswell?
public DateTime? GetSomteDate(int SomeID)
{
DateTime? LimitDate= null;
if (_entities.Connection.State == System.Data.ConnectionState.Closed)
_entities.Connection.Open();
using (EntityCommand c = new EntityCommand("MyEntities.GetSomeDate", (EntityConnection)this._entities.Connection))
{
c.CommandType = System.Data.CommandType.StoredProcedure;
EntityParameter paramSomeID = new EntityParameter("SomeID", System.Data.DbType.Int32);
paramSomeID.Direction = System.Data.ParameterDirection.Input;
paramSomeID.Value = SomeID;
c.Parameters.Add(paramSomeID);
var x = c.ExecuteScalar();
if (x != null)
LimitDate = (DateTime)x;
return LimitDate.Value;
};
}