Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Expression error in ASP.NET

Posted on 2007-08-10
5
Medium Priority
?
1,392 Views
Last Modified: 2013-11-05
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
Comment
Question by:sl1nger
  • 3
5 Comments
 
LVL 22

Expert Comment

by:DarkoLord
ID: 19673929
Hi,

Can you just use the CDate(drAllFac("Time_Start")) instead of formatting the time first?
0
 

Author Comment

by:sl1nger
ID: 19677292
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
 
LVL 22

Accepted Solution

by:
DarkoLord earned 2000 total points
ID: 19677388
Okay, it appears that some dates are "null" (empty) in your database. What would you like to do with them?
0
 
LVL 25

Expert Comment

by:DBAduck - Ben Miller
ID: 19678002
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
 
LVL 22

Expert Comment

by:DarkoLord
ID: 19678847
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question