SqlDataReader未将对象应用设置到对象实例
2011-09-02 10:34
423 查看
在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以后再说吧。
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以后再说吧。
相关文章推荐
- SqlDataReader使用实例
- ADO.NET读书笔记系列之------SqlCommander和SqlDataReader对象
- c#配置问题以及简单防止sql注入,连接池问题,sqldatareader对象对于connection对象的释放
- 利用SqlCommand和SqlDataReader对象操作数据库
- 数据读取器对象SqlDataReader与数据适配器对象SqlDataAdapter的使用
- 获取sqlDataReader对象Read()方法读取流的字段值的四种方法
- QTP中虚拟对象设置及应用实例
- 读书笔记系列之------SqlCommander和SqlDataReader对象
- SqlCommander和SqlDataReader对象
- 判断SqlDataReader 记录集是否为空的应用(原)
- 未将对象引用设置到对象的实例 Microsoft.Office.Server.Administration.SqlSessionStateResolver
- 黑马程序员_学习日记47_615数据库开发及ADO.Net(连接字符串、SqlDataReader对象、连接池)
- C#连接数据库sqlserver2005,执行sql,得到SqlDataReader结果的实例
- 转载:QTP中虚拟对象设置及应用实例
- C#使用SQL DataReader访问数据的优点和实例
- 数据读取器对象SqlDataReader与数据适配器对象SqlDataAdapter的使用
- ADO.NET读书笔记系列之------SqlCommander和SqlDataReader对象
- 简述ADO.NET中的SqlDataReader对象
- ashx中应用HttpContext.Current.Session ,呈现未将对象引用设置到实例(转)
- 数据读取器对象SqlDataReader与数据适配器对象SqlDataAdapter的使用