在winform开发中,?为了实现多层架构做到对数据库的访问单独操作,建了一个SQLServer数据库操作助手类。在此类中有一些函数是返回SqlDataReader类数据的函数。于是在调用的时候会这样子申明:
SqlDataReader datareader = null;
或者:
SqlDataReader datareader = new SqlDataReader();
调试的时候报错:未将对象应用设置到对象实例。
网上的解答是:SqlDataReader的申明必须是SqlDataReader sqlReader = command.ExecuteReader();
?
而且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; }
难道就不能返回SqlDatareader吗?
有人建议改用公共类型DataTable,可以试试。至于SqlDatareader以后再说吧。
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|