[转]CommandBehavior枚举的SingleRow成员及System.Data.CommandBehavior 枚举说明

性能小常识】CommandBehavior枚举的SingleRow成员

CommandBehavior枚举的SingleRow成员设置查询应返回一行。

执行查询可能会影响数据库的状态。一些 .NET Framework 数据提供程序可能(但不要求)使用此信息来优化命令的性能。用 OleDbCommand 对象的 ExecuteReader 方法指定 SingleRow 时,用于 OLE DB 的 .NET Framework 数据提供程序使用 OLE DB IRow 接口(如果可用)执行绑定。否则,它使用 IRowset 接口。如果您的 SQL 语句应该只返回一行,则指定 SingleRow 还可以提高应用程序性能。在执行返回多个结果集的查询时,可以指定 SingleRow。在这种情况下,仍返回多个结果集,但每个结果集只有一行。 

 

 

System.Data.CommandBehavior 枚举说明

Posted on 2005-06-27 10:47 房客 阅读(237) 评论(0)   编辑   收藏 网摘 所属分类: CodeHide


SqlDataReader   sdr = new SqlDataReader();
SqlCommand SCmd = new SqlCommand();

sdr =SCmd.ExecuteReader(CommandBehavior.CloseConnection);


其中对于CommandBehavior的说明如下:

 提供对查询结果和查询对数据库的影响的说明。

CommandBehavior是一个枚举。其成员和说明分别如下:

1、public static const System.Data.CommandBehavior CloseConnection
    System.Data.CommandBehavior 的成员

摘要:
 在执行该命令时,如果关闭关联的 DataReader 对象,则关联的 Connection 对象也将关闭。 

2、public static const System.Data.CommandBehavior Default
    System.Data.CommandBehavior 的成员

摘要:
 此查询可能返回多个结果集。执行查询可能会影响数据库状态。Default 不设置 System.Data.CommandBehavior 标志,因此调用 ExecuteReader(CommandBehavior.Default) 在功能上等效于调用 ExecuteReader()。 

3、public static const System.Data.CommandBehavior KeyInfo
    System.Data.CommandBehavior 的成员

摘要:
 此查询返回列和主键信息。执行此查询时不锁定选定的行。   当使用 KeyInfo 时,用于 SQL Server 的 .NET Framework 数据提供程序将 FOR BROWSE 子句追加到正在执行的语句。用户应该注意潜在的副作用,例如对 SET FMTONLY ON 语句的使用产生的干扰。有关更多信息,请参见“SQL Server 联机图书”。 

4、public static const System.Data.CommandBehavior SchemaOnly
    System.Data.CommandBehavior 的成员

摘要:
 此查询只返回列信息,而不影响数据库状态。 

5、public static const System.Data.CommandBehavior SequentialAccess
    System.Data.CommandBehavior 的成员

摘要:
 提供一种方法,以便 DataReader 处理包含带有大二进制值的列的行。SequentialAccess 不是加载整行,而是使 DataReader 将数据作为流来加载。然后可以使用 GetBytes 或 GetChars 方法来指定开始读取操作的字节位置以及正在返回的数据的有限的缓冲区大小。   当指定 SequentialAccess 时,尽管无需读取每个列,但是需要按照列的返回顺序读取它们。一旦已经读过返回的数据流中某个位置的内容,就不能再从 DataReader 中读取该位置或该位置之前的数据。当使用 System.Data.OleDb.OleDbDataReader 时,可重新读取当前列的值,直到读过它。当使用 System.Data.SqlClient.SqlDataReader 时,一次只能读取一个列值。 

6、public static const System.Data.CommandBehavior SingleResult
    System.Data.CommandBehavior 的成员

摘要:
 查询返回一个结果集。 

7、public static const System.Data.CommandBehavior SingleRow
    System.Data.CommandBehavior 的成员

摘要:
 查询应返回一行。执行查询可能会影响数据库状态。一些 .NET Framework 数据提供程序可能(但不要求)使用此信息来优化命令的性能。在用 System.Data.OleDb.OleDbCommand 对象的 System.Data.OleDb.OleDbCommand.ExecuteReader 方法指定 System.Data.CommandBehavior.SingleRow 时,用于 OLE DB 的 .NET Framework 数据提供程序使用 OLE DB IRow 接口(如果可用)执行绑定。否则,它使用 IRowset 接口。如果您的 SQL 语句应该只返回一行,则指定 System.Data.CommandBehavior.SingleRow 还可以提高应用程序性能。   在执行返回多个结果集的查询时,可以指定 SingleRow。在这种情况下,仍返回多个结果集,但每个结果集只有一行。 

而其枚举具体定义如下:

public enum CommandBehavior
Name:System.Data.CommandBehavior
Assembly:System.Data, Version=1.0.5000.0

[Flags]
public enum CommandBehavior
{
      // Fields
      CloseConnection = 0x20,
      Default = 0,
      KeyInfo = 4,
      SchemaOnly = 2,
      SequentialAccess = 0x10,
      SingleResult = 1,
      SingleRow = 8
}

应用程序: Asd.AgingTestRack.IMP.SunnyUI.WinAPP.exe Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止。 异常信息: System.Data.SQLite.SQLiteException 在 System.Data.SQLite.SQLite3.Prepare(System.Data.SQLite.SQLiteConnection, System.Data.SQLite.SQLiteCommand, System.String, System.Data.SQLite.SQLiteStatement, UInt32, System.String ByRef) 在 System.Data.SQLite.SQLiteCommand.BuildNextCommand() 在 System.Data.SQLite.SQLiteCommand.GetStatement(Int32) 在 System.Data.SQLite.SQLiteDataReader.NextResult() 在 System.Data.SQLite.SQLiteDataReader..ctor(System.Data.SQLite.SQLiteCommand, System.Data.CommandBehavior) 在 System.Data.SQLite.SQLiteCommand.ExecuteReader(System.Data.CommandBehavior) 在 System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(System.Data.CommandBehavior) 在 System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(System.Data.CommandBehavior, System.Threading.CancellationToken) 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition+<ExecuteStoreCommandsAsync>d__26.MoveNext() 异常信息: System.Data.Entity.Core.EntityCommandExecutionException 在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition+<ExecuteStoreCommandsAsync>d__26.MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan+<ExecuteAsync>d__10`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Utilities.TaskExtensions+CultureAwaiter`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetResult() 在 System.Data.Entity.Core.Objects.ObjectContext+<ExecuteInTransactionAsync>d__156`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Utilities.TaskExtensions+CultureAwaiter`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetResult() 在 System.Data.Entity.Core.Objects.ObjectQuery`1+<GetResultsAsync>d__43[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Utilities.TaskExtensions+CultureAwaiter`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetResult() 在 System.Data.Entity.Internal.LazyAsyncEnumerator`1+<FirstMoveNextAsync>d__9[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions+<SingleOrDefaultAsync>d__31`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Utilities.TaskExtensions+CultureAwaiter`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetResult() 在 System.Data.Entity.Internal.Linq.InternalSet`1+<FindInStoreAsync>d__12[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Data.Entity.Internal.Linq.InternalSet`1+<FindInternalAsync>d__9[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetResult() 在 Asd.AgingTestRack.IMP.DB.DAO.HistoryDataDao+<AddOrUpdateHistoryDataAsync>d__1`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.GetResult() 在 Asd.AgingTestRack.IMP.DB.DAO.HistoryDataDao+<Addr4>d__5.MoveNext() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) 在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task) 在 Asd.AgingTestRack.IMP.SunnyUI.WinAPP.FrmRunPlant+<ChangeAgItemStatus2>d__53.MoveNext() 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1(System.Object) 在 System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object) 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 分析报错原因
06-08
09:45:58:967 引发的异常:“System.Data.Entity.Infrastructure.DbUpdateException”(位于 EntityFramework.dll 中) 09:45:58:967 System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SQLite.SQLiteException: constraint failed 09:45:58:967 NOT NULL constraint failed: r2TabHistoryData.Batch 09:45:58:967 在 System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) 09:45:58:967 在 System.Data.SQLite.SQLiteDataReader.NextResult() 09:45:58:967 在 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) 09:45:58:967 在 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) 09:45:58:967 在 System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior) 09:45:58:967 在 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) 09:45:58:967 在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c.<Reader>b__6_0(DbCommand t, DbCommandInterceptionContext`1 c) 09:45:58:967 在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) 09:45:58:967 在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) 09:45:58:967 在 System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) 09:45:58:967 在 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) 09:45:58:967 在 System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues) 09:45:58:967 在 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() 09:45:58:967 --- 内部异常堆栈跟踪的结尾 --- 09:45:58:967 在 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() 09:45:58:967 在 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<>c.<Update>b__21_0(UpdateTranslator ut) 09:45:58:967 在 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction) 09:45:58:967 在 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() 09:45:58:967 在 System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__153_0() 09:45:58:967 在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) 09:45:58:967 在 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) 09:45:58:967 在 System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass148_0.<SaveChangesInternal>b__0() 09:45:58:967 在 System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation) 09:45:58:967 在 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) 09:45:58:967 在 System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) 09:45:58:967 在 System.Data.Entity.Internal.InternalContext.SaveChanges() 09:45:58:967 --- 内部异常堆栈跟踪的结尾 --- 09:45:58:967 在 System.Data.Entity.Internal.InternalContext.SaveChanges() 09:45:58:967 在 System.Data.Entity.Internal.LazyInternalContext.SaveChanges() 09:45:58:967 在 System.Data.Entity.DbContext.SaveChanges() 09:45:58:967 在 Asd.AgingTestRack.IMP.DB.ASD_AgingRack_db.SaveChanges() 位置 C:\Users\asd\Desktop\调试\Asd.AgingTestRack\Asd.AgingTestRack.IMP.DB\ASD_AgingRack_db.cs:行号 55: Database update error during SaveChanges. 分析错误
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值