C#: Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type.

Today I got "Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type." error in the C# application. After my trace, it is caused by this line:

DateTime? moveOutDate = dt.Rows[0].Field("MoveOutDate");

You should make it as:

DateTime? moveOutDate = dt.Rows[0].Field("MoveOutDate");

Comments

Anonymous said…
Thanks for this, it looked like quite an imposing error until i found your post :-)
J R Bishnoi said…
but crystal report don't support Nullable variable, any solution..

Popular posts from this blog

Post packing slip of sales order in X++