Click here to Skip to main content
15,939,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having an error Specified cast is not valid

MIDL
//this is the code in the booking form
// time is public static
time = TimeSpan.Parse(dtpTime.Value.ToShortTimeString());
//this is the code in another form
while (rdr.Read())
{
    for (int i = 0; i < rdr.FieldCount; i++)
    {
        if ((TimeSpan)rdr[6] > Booking.time)
        {
            // etc etc
        }
    }
}
Posted
Updated 19-Mar-10 0:53am
v2

I'm assuming rdr.Read() returns a string? If so, you will need to use Timespan.Parse or Timespan.TryParse to parse the string, you cannot just cast as there is no implicit or explicit conversion from string defined.
 
Share this answer
 
So what is the data type of the item?
:)
 
Share this answer
 
What is rdr?
What is rdr[6]?
Have you looked using the debugger? Put a breakpoint on the "if ((TimeSpan)rdr[6] > Booking.time)" line and see what the rdr array contains.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900