Search the web
Sign In
New User? Sign Up
StrongTypes · Free .NET Generics Help
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Generic SqlDataReader to List   Message List  
Reply | Forward Message #20 of 44 |
I'm trying to loop through a reader and put all the values into a
generic list.

public T RStoList<T>(SqlDataReader rdr, int index)
{
List<T> list = new List<T>();

while (rdr.Read())
{
list.Add(rdr.GetValue(index));
}

return list;
}

It's not letting me add the object to the list though. I need to
somehow convert the value from the reader into the right type T.

Tried this without success:

list.Add(Convert.ChangeType(rdr.GetValue(index),typeof(T)));

Ideas?










Fri May 12, 2006 8:01 pm

sureshotnj
Offline Offline
Send Email Send Email

Forward
Message #20 of 44 |
Expand Messages Author Sort by Date

I'm trying to loop through a reader and put all the values into a generic list. public T RStoList<T>(SqlDataReader rdr, int index) { List<T> list = new...
sureshotnj
Offline Send Email
May 15, 2006
1:58 am

Since GetValue returns an object, you'd have to cast it to T. public T RStoList<T>(SqlDataReader rdr, int index) { List<T> list = new List<T>(); while...
Ryan Olshan
teranetlists
Offline Send Email
May 15, 2006
2:01 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help