在以下代码中,command是一个已经设置好的DbCommand:
using( var dataReader = command.ExecuteReader() /*The actual execution of the query takes relatively little time.*/ ) {
while( dataReader.Read() ) {
// These are what take all of the time. Replacing them all with reader.GetValues( myArray ) has no impact.
val0 = dataReader.GetValue( 0 );
val1 = dataReader.GetValue( 1 );
val2 = dataReader.GetValue( 2 );
}
}
我目前处理的查询的大部分时间都花在了GetValue调用上.是不是每次调用GetValue都要往返数据库?看起来是这样,而且这似乎效率很低.正如代码所指出的,try 使用GetValues()一次性完成这项任务并没有什么不同.有没有办法一次把整排人都弄到手?更好的是,有没有一种方法可以一次性获得整个结果集?
谢谢你.