Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

How add record to IEnumerable(Of Type) object?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ronald S. Cook - 27 Mar 2008 21:41 GMT
I'm used to my class returning records -- let's say employee records -- in a
DataSet (ok, so DataTable within a DataSet technically).

But now, my class is returning those records as IEnumerable(Of Employee).

While I can still just as easily bind this to a ComboBox, ListBox,
DataGridView, etc., I'm not understanding how to add records to it.

If I try to add a record to, say, the ListBox, it will tell me it can't
because the control is bound.

So, how can I add records to ultimately the IEnumerable(Of Employee) object?

Thanks,
Ron
Jon Skeet [C# MVP] - 27 Mar 2008 22:05 GMT
> I'm used to my class returning records -- let's say employee records -- in a
> DataSet (ok, so DataTable within a DataSet technically).
[quoted text clipped - 8 lines]
>
> So, how can I add records to ultimately the IEnumerable(Of Employee) object?

You can't, without casting to something which directly supports
addition. Bear in mind that IEnumerable(Of Employee) may be:

1) Implemented by an array of fixed size
2) Read-only
3) Generated dynamically with no concept of addition

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Mick Wilson - 27 Mar 2008 22:15 GMT
> I'm used to my class returning records -- let's say employee records -- in a
> DataSet (ok, so DataTable within a DataSet technically).
[quoted text clipped - 11 lines]
> Thanks,
> Ron

Is the compiler giving you the error? If so, I think your issue is
that the IEnumerable interface defines only the method for the
Enumerator. If you want the other methods back to manipulate the
object, you should probably cast it to the run-time type you're
expecting to work with (or modify the return type of the class).

Thanks,
Mick

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.