views:

57

answers:

1

I want to select many rows from my SQL Server database and combine them in a certain manner. Currently, I've been using the following method to get these rows:

SqlDataSource mySource = new SqlDataSource("ConnectionString","SelectStatement");
IEnumerable myEnum = mySource.Select(DataSourceSelectArguments.Empty);
IEnumerator myCount = myEnum.GetEnumerator();
while(myCount.MoveNext()) //Iterate through each row
{
    DataRowView myView = (DataRowView)myCount.Current; //This is the current row
    //Do something with this row
}

I feel like there must be a better way of doing this. Any suggestions?

A: 

Why dont't you use foreach instead? foreach is meant to work on Enumerable types. something like

foreach (var currentView in mySource.Select(DataSourceSelectArguments.Empty)) { // Do something with currentView (may need to give it a type if you are interested in it. }

Chetan