I use a full class full of extension methods for dealing with
NULL values, which greatly simplifies retrieving potentially null values from database calls.
You would need to trans-code this small sample into VB.Net, but you should be able to do that rather easily.This line will always give me a valid DateTime.
DateTime GpsTime = row["GpsTime"].FixDate();
This is how that extension method is defined. Again this is C# and would need to be transcoded into VB.
namespace System {
public static partial class PublicExtensions {
public static DateTime FixDate(this object NullableDate, string DefaultDateString = "01/01/0001") {
DateTime ReturnValue;
if (NullableDate != null) {
try { ReturnValue = DateTime.Parse(NullableDate.FixString(DefaultDateString)); }
catch (Exception) { if (!DateTime.TryParse(DefaultDateString, out ReturnValue)) { ReturnValue = new DateTime(0); } }
}
else { if (!DateTime.TryParse(DefaultDateString, out ReturnValue)) { ReturnValue = new DateTime(0); } }
return ReturnValue;
}
}
}
Reference:
Extension Methods (Visual Basic) | Microsoft Docs[
^]