本文整理汇总了C#中CommandBehavior.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# CommandBehavior.HasFlag方法的具体用法?C# CommandBehavior.HasFlag怎么用?C# CommandBehavior.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandBehavior
的用法示例。
在下文中一共展示了CommandBehavior.HasFlag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryXml
public static XmlDocument QueryXml(
this SqlConnection connection,
string sql,
object parameters = null,
CommandType commandType = CommandType.StoredProcedure,
CommandBehavior commandBehavior = CommandBehavior.Default,
int? commandTimeout = null,
IDbTransaction transaction = null,
object outputParameters = null)
{
return connection.ExecuteAndAutoClose(
c =>
{
using (var cmd = (SqlCommand)c.CreateCommand(sql, parameters, commandType, commandTimeout, transaction))
{
cmd.OutputParameters(outputParameters);
return cmd.ExecuteXml();
}
},
commandBehavior.HasFlag(CommandBehavior.CloseConnection));
}
示例2: ExecuteDbDataReader
/// <summary>
/// Executes the command text against the connection.
/// </summary>
/// <returns>
/// A task representing the operation.
/// </returns>
/// <param name="behavior">An instance of <see cref="T:System.Data.CommandBehavior"/>.</param><exception cref="T:System.Data.Common.DbException">An error occurred while executing the command text.</exception><exception cref="T:System.ArgumentException">An invalid <see cref="T:System.Data.CommandBehavior"/> value.</exception>
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
var channel = m_connection.BeginExecuteCommand(this);
try
{
var dataRequest = CreateRequest(false, !behavior.HasFlag(CommandBehavior.SchemaOnly));
var response = SendCommand(channel, dataRequest, CreateRequestParams(), null);
var streamHolder = PqlDataConnection.ReaderStreams.Take(m_connection.CancellationTokenSource.Token);
try
{
streamHolder.Item.Attach(response.Stream);
return new PqlDataReader(m_connection, streamHolder.Item, streamHolder, response);
}
catch
{
streamHolder.Dispose();
response.Close();
throw;
}
}
catch
{
m_connection.ConfirmExecutionCompletion(false);
throw;
}
}