Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional .NET 2.0 Generics
This is the forum to discuss the Wrox book Professional .NET 2.0 Generics by Tod Golding; ISBN: 9780764559884
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional .NET 2.0 Generics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 21st, 2006, 10:52 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Casting

Public Function GetItems(Of T)(ByVal sql As String) As Collection(Of T)
        Dim selectCmd As New OleDbCommand(sql, dbConn)
        Dim retVal As New Collection(Of T)
        Dim dataReader As OleDbDataReader = selectCmd.ExecuteReader()
        While (dataReader.Read() = True)
            retVal.Add(DirectCast(dataReader(0), T))
        End While

        Return retVal
    End Function

I keep on getting an error:

Message="Unable to cast object of type 'System.Int32' to type 'Architecture.Employees'." What am i doing wrong?

Reply With Quote
  #2 (permalink)  
Old June 21st, 2006, 11:50 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To make my statement clearer above please give an example of passing a Person class to the function and casting a reader object to the class. Thanks.

Reply With Quote
  #3 (permalink)  
Old November 13th, 2007, 04:55 PM
Registered User
 
Join Date: Nov 2007
Location: MIAMI, FL, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am having a similar error.
I am using an OracleDataReader.


FREDYCOREA
Reply With Quote
  #4 (permalink)  
Old November 19th, 2007, 04:49 PM
Registered User
 
Join Date: Nov 2007
Location: MIAMI, FL, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did anybody find out why this code do not work.
I tried it several ways to no avail, still the same casting error message.


FREDYCOREA
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting - Can you help koco C# 1 September 24th, 2007 09:41 AM
Casting Problem liorlankri ASP.NET 1.x and 2.0 Application Design 2 January 2nd, 2007 03:31 AM
casting ravibodani Access 1 April 4th, 2006 02:19 PM
Casting question shantawn J2EE 4 August 2nd, 2005 03:40 AM
Dynamic Casting pareshsoft C# 2 December 1st, 2004 12:12 AM



All times are GMT -4. The time now is 10:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.