Wow. This thread has really generated a flood of information--much of it accurate, some of it not so...
I think the fundamental problem here is not that ADO.NET does not support cursors (because it does and I'll get to that later), but that you want to "loop" through a table. Let's talk a moment about the reasons behind wanting to visit each row.
a.. Suppose the user wants to search for something and feels that they have to visit each row in a table looking for a match. If you have a table larger than a few dozen rows would you simply display all of the rows on the screen and let the user visually search? Most of us wouldn't unless you have a screen with really tiny fonts and issue the user a magnifying glass. We would ask for a search criteria or two and use these as WHERE clause arguments to focus the search on a few (dozen) rows. This does not require that you move the entire table over the wire and return it to the user. There are cases where an application needs to perform complex operations (such as graphical representation of data), but again, being selective about what you return is important. Most of the time, the user can help narrow the search. It's far faster (and easier on all other users) if you only fetch what the user can deal with at the moment. You can speed up the process by requerying for more data behind the scenes while they peruse the dozen or so rows you just presented. Having fetched the entire table only to have the user abandon the search after the first couple of pages is a big waste of resources.
b.. Suppose you want to manipulate the rows in a table--that is, change values in selected rows based on some criteria. For example, you wanted to find any Part in the Parts table that needed to be reordered and execute some code to start the reorder process. In this case all of the processing can be done server-side (assuming you aren't using JET). Simply write a SP that performs the work on the server--updating or inserting rows where necessary. In this case no data is brought to the client--only the results of the operation. While it's rare to change all the rows in a table, this can be easily done (even with JET) by creating an UPDATE query that makes the changes (again without bringing the rows to the client (except for JET which does all of its physical IO over the wire).
c.. If you need to produce a report, there are times when the report needs to perform calculations or aggregates on all of the rows in a table. In this case we suggest that you use a server-side reporting engine like Reporting Services or use "roll-up" techniques to create a summary table using server-side code that eliminates the need to bring the raw data to the client for processing.
The point here is that when using SQL Server (or Oracle and other real "server" DBMSs) that you should avoid bringing the data to the client for processing. Do the processing on the server. It's faster, it requires less network overhead, it's less likely to lock up the data for others, and it's more scalable. Capture parameters from the user and bring "results" to the client--don't make them do all the work.
As for creating cursors using ADO.NET--while ADO.NET does not have a server-side cursor implementation in the current version (Whidbey does), you can create cursors today by using the CREATE CURSOR ANSI SQL calls. I explain how to do this in my session at VSLive in San Francisco next month. See
http://www.betav.com/pinnacle.htm "...Doing the Impossible (Again)" for details (you might have to subscribe to get a copy).
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________