📄 enumeratedatareader.cs
字号:
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Microsoft.Mobile.Data
{
/// <summary>
/// Used to enumerate a data reader.
/// </summary>
[SuppressMessage("Microsoft.Naming",
"CA1710:IdentifiersShouldHaveCorrectSuffix",
Justification = "More readable as EnumerateDataReader")]
public class EnumerateDataReader : RowEnumerator
{
#region Fields
private IDataReader _dataReader;
#endregion
#region Constructor(s) and Dispose
/// <summary>
/// Build the enumerator passing in the DataReader to enumerate.
/// </summary>
/// <param name="dataReader">DataReader to enumerate</param>
public EnumerateDataReader(IDataReader dataReader)
{
if (dataReader == null)
{
throw new ArgumentException("Cannot be null.", "dataReader");
}
_dataReader = dataReader;
}
/// <summary>
/// Close and release the DataReader
/// </summary>
protected override void Dispose(bool disposing)
{
_dataReader.Close();
_dataReader.Dispose();
}
#endregion
#region Methods
/// <summary>
/// Move forward to the next row.
/// </summary>
/// <returns>Returns false if no more rows are present</returns>
public override bool MoveNext()
{
bool result;
string tempString;
// read a row from the data reader
result = _dataReader.Read();
// if a row was read then build a Row
if (result)
{
// build Row current row from DataReader
currentRow = new DataRow();
// loop through the fields and building the Columns
// and add them to the row
for (int loop = 0; loop < _dataReader.FieldCount; loop++)
{
tempString = _dataReader.GetName(loop);
currentRow.Add(tempString,
_dataReader[loop]);
}
}
else
{
// if no more rows set the currentRow to null
currentRow = null;
}
return result;
}
/// <summary>
/// Reset is not implemented since a DataReader is forward only
/// </summary>
public override void Reset()
{
throw new InvalidOperationException("DataReaders are forward only. Use a different enumerator if you need to start over.");
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -