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
.NET Framework 3.5 For discussion of the Microsoft .NET Framework 3.5.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 3.5 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 Search this Thread Display Modes
  #1 (permalink)  
Old November 19th, 2007, 04:53 PM
Registered User
 
Join Date: Nov 2007
Location: MIAMI, FL, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default NET Generics

I've got the book .Net 2.0 Generics, when I tried the following code from page 97, I receive a casting error message:


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?




FREDYCOREA
Reply With Quote
  #2 (permalink)  
Old February 21st, 2008, 10:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

What are you passing into the T parameter? Are you passing Integer, or Employees object? How are you using this method? That will give some insight.

Thanks.

Brian
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Generics in 3.0 sikanderwaheed C# 2008 aka C# 3.0 1 May 5th, 2008 08:30 AM
Application of generics micmit C# 2005 0 October 12th, 2006 08:10 PM
Generics Related error in my code, I think??? rodmcleay Generics 1 August 3rd, 2006 12:02 AM
Problem with generics collections demitry .NET Framework 2.0 4 November 24th, 2005 06:39 AM



All times are GMT -4. The time now is 07:23 PM.


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