MSDN帮助原文:
若要创建 SqlDataReader,必须调用 SqlCommand 对象的 ExecuteReader 方法,而不要直接使用构造函数。
ExecuteDataReader() 的函数体:
public SqlDataReader ExecuteReader()
{
SqlStatistics statistics = null;
SqlDataReader reader;
IntPtr ptr;
Bid.ScopeEnter(out ptr, "<sc.SqlCommand.ExecuteReader|API> %d#", this.ObjectID);
try
{
statistics = SqlStatistics.StartTimer(this.Statistics);
reader = this.ExecuteReader(CommandBehavior.Default, "ExecuteReader");
}
finally
{
SqlStatistics.StopTimer(statistics);
Bid.ScopeLeave(ref ptr);
}
return reader;
}
SqlDataReader的构造函数:
internal SqlDataReader(SqlCommand command, CommandBehavior behavior)
{
this._recordsAffected = -1;
this.ObjectID = Interlocked.Increment(ref _objectTypeCount);
this._command = command;
this._commandBehavior = behavior;
if (this._command != null)
{
this._timeoutSeconds = command.CommandTimeout;
this._connection = command.Connection;
if (this._connection != null)
{
this._statistics = this._connection.Statistics;
this._typeSystem = this._connection.TypeSystem;
}
}
this._dataReady = false;
this._metaDataConsumed = false;
this._hasRows = false;
this._browseModeInfoConsumed = false;
}
不是没有构造函数,不给你用罢了
杨连国
|
菜鸟二级
|园豆:295
|
2008-04-17 12:56