2 回答
![?](http://img1.sycdn.imooc.com/545850c80001ebf202200220-100-100.jpg)
TA贡献1875条经验 获得超3个赞
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; } 不是没有构造函数,不给你用罢了
- 2 回答
- 0 关注
- 585 浏览
添加回答
举报