2 回答

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 關注
- 610 瀏覽
添加回答
舉報