• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1445
  • Last Modified:

Expression error in ASP.NET

I think my error might be referring to a date format, but I'm not sure.  Does anyone know what this error is for?

Argument 'Expression' is not a valid value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Expression' is not a valid value.

Source Error:


Line 507:            Dim newRow As DataRow
Line 508:            For Each drAllFac In dtAllFac.Rows
Line 509:                If CDate(Format(drAllFac("Time_Start"), "h:mm tt")) > CDate(Format(drAllFac("Time_Stop"), "hh:mm tt")) Then

 
0
sl1nger
Asked:
sl1nger
  • 3
1 Solution
 
DarkoLordCommented:
Hi,

Can you just use the CDate(drAllFac("Time_Start")) instead of formatting the time first?
0
 
sl1ngerAuthor Commented:
This is what I get...

Conversion from type 'DBNull' to type 'Date' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Date' is not valid.

Source Error:


Line 507:            Dim newRow As DataRow
Line 508:            For Each drAllFac In dtAllFac.Rows
Line 509:                If CDate(drAllFac("Time_Start")) > CDate(drAllFac("Time_Stop")) Then

 
0
 
DarkoLordCommented:
Okay, it appears that some dates are "null" (empty) in your database. What would you like to do with them?
0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
If there are nulls in the data, then you should check to see if it is = DBNull.Value before you try to use it in any function like CDate().

if drAllFac("Time_Start") <> DBNull.Value Then
     If CDate(drAllFac("Time_Start")) > CDate(drAllFac("Time_Stop")) Then
        ' do something
     End If
End If

Ben.
0
 
DarkoLordCommented:
However this changes the logic, so it's probably beter to use IsNull function in SQL query and set a default value for null dates
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now