ADO.Net 浅析(四)
前面大概讲了一下通过连接方式访问数据库的过程,其过程总结如下
1创建连接,配置连接打开连接
2创建命令,指定命令的连接对象
3执行命令并获得datareader对象(此处.datareader对象通过cmd.ExecuteReader获得,无法使用new datareader())
4使用datareader.Read()方法,逐行获取数据记录
sqldatareader构造函数如下
internal SqlDataReader(SqlCommand command, CommandBehavior behavior) {
SqlConnection.VerifyExecutePermission();
_command = command;
_commandBehavior = behavior;
if (_command != null) {
_timeoutSeconds = command.CommandTimeout;
_connection = command.Connection;
if (_connection != null) {
_statistics = _connection.Statistics;
_typeSystem = _connection.TypeSystem;
}
}
_dataReady = false;
_metaDataConsumed = false;
_hasRows = false;
_browseModeInfoConsumed = false;
}
SqlConnection.VerifyExecutePermission();
_command = command;
_commandBehavior = behavior;
if (_command != null) {
_timeoutSeconds = command.CommandTimeout;
_connection = command.Connection;
if (_connection != null) {
_statistics = _connection.Statistics;
_typeSystem = _connection.TypeSystem;
}
}
_dataReady = false;
_metaDataConsumed = false;
_hasRows = false;
_browseModeInfoConsumed = false;
}
可以看到,其没有public的构造函数.