我想从我的SQL Server数据库中选择许多行,并以某种方式将它们组合在一起。目前,我一直在使用以下方法来获取这些行:
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
}
我觉得必须有更好的方法来做到这一点。有什么建议吗?
答案 0 :(得分:0)
为什么不使用foreach呢? foreach旨在处理可枚举类型 类似的东西:
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)
}