在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以后再说吧。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。