Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to populate a IdataReader.
VB
Private Sub populate(ByVal objread as IdataReader, ByVal objL as DistrictPreviousTrends)
    ObjL.CurrentYear = objRead.GetDateTime(0)
End Sub

But I get the following error
"specified cast is not valid"
Posted
Updated 25-Oct-11 10:48am
v4
Comments
André Kraak 25-Oct-11 16:49pm    
What is the type of ObjL.CurrentYear?
Sneh_Blose 25-Oct-11 16:55pm    
it is of Date.
Sneh_Blose 25-Oct-11 16:55pm    
it is of type date
Simon Bang Terkildsen 25-Oct-11 16:58pm    
really? that must be your own type then. in any case SA's solution still applies.

1 solution

Sure, how can you assign between numeric value (ObjL.CurrentYear) and structure System.DateTime?

Most likely, your ObjL.CurrentYear is int. In this case, use

VB
ObjL.CurrentYear = objRead.GetDateTime(0).Year


Anyway, see http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA
 
Share this answer
 
v2
Comments
Simon Bang Terkildsen 25-Oct-11 16:58pm    
Right
Sergey Alexandrovich Kryukov 25-Oct-11 17:33pm    
Thank you, Simon.
--SA
Espen Harlinn 25-Oct-11 17:31pm    
That's a reasonable guess, my 5
Sergey Alexandrovich Kryukov 25-Oct-11 17:33pm    
Hope so; thank you, Espen.
--SA

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

  Print Answers RSS


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