本文整理汇总了C#中IDbCommand.Cancel方法的典型用法代码示例。如果您正苦于以下问题:C# IDbCommand.Cancel方法的具体用法?C# IDbCommand.Cancel怎么用?C# IDbCommand.Cancel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbCommand
的用法示例。
在下文中一共展示了IDbCommand.Cancel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSchemaTable
//private DataTable GetSchemaTable(IDbCommand sqlSelectCommand)
protected virtual DataTable GetSchemaTable(IDbCommand sqlSelectCommand)
{
DataTable dataTableSchema = new DataTable();
bool isClosed = ConnectionState.Closed == _sqlConnection.State;
try
{
if (isClosed)
{
_sqlConnection.Open();
}
IDataReader sqlDataReader = sqlSelectCommand.ExecuteReader(CommandBehavior.KeyInfo);
dataTableSchema = sqlDataReader.GetSchemaTable();
sqlSelectCommand.Cancel();
sqlDataReader.Close();
}
catch (NotSupportedException)
{
//swallow this since .Close() op isn't supported on all DB targets (e.g., SQLCE)
}
finally
{
//Only close connection if connection was not passed to constructor
if (!_passedconnection)
{
if (_sqlConnection.State != ConnectionState.Closed)
{
_sqlConnection.Close();
}
}
}
return dataTableSchema;
}
示例2: PopulateResults
/// <summary>
/// Executes an SQL query and populates a given <see cref="QueryResults" /> instance with the results.
/// </summary>
/// <param name="results"><see cref="QueryResults" /> instance to populate with results.</param>
/// <param name="command">SQL command to execute.</param>
/// <param name="result"><see cref="AsyncResult"/> instance to use to mark state changes.</param>
/// <param name="messages"><see cref="StringBuilder" /> instance to which to append messages.</param>
/// <param name="IncludeExecutionPlan">If true indciates that the query execution plans are expected to be contained
/// in the results sets; otherwise, false.</param>
private static void PopulateResults(QueryResults results, IDbCommand command, AsyncQueryRunner.AsyncResult result, StringBuilder messages, bool IncludeExecutionPlan)
{
QueryPlan plan = new QueryPlan();
using (var reader = command.ExecuteReader())
{
do
{
// Check to see if the resultset is an execution plan
if (IncludeExecutionPlan && reader.FieldCount == 1 && reader.GetName(0) == "Microsoft SQL Server 2005 XML Showplan")
{
if (reader.Read())
{
result.HasOutput = true;
plan.AppendStatementPlan(reader[0].ToString());
}
}
else
{
if (reader.FieldCount == 0)
{
if (reader.RecordsAffected >= 0)
{
messages.AppendFormat("({0} row(s) affected)\n\n", reader.RecordsAffected);
}
continue;
}
var resultSet = new ResultSet();
resultSet.MessagePosition = messages.Length;
results.ResultSets.Add(resultSet);
for (int i = 0; i < reader.FieldCount; i++)
{
var columnInfo = new ResultColumnInfo();
columnInfo.Name = reader.GetName(i);
ResultColumnType colType;
if (ResultColumnInfo.ColumnTypeMap.TryGetValue(reader.GetFieldType(i), out colType))
{
columnInfo.Type = colType;
}
resultSet.Columns.Add(columnInfo);
}
int currentRow = 0;
while (reader.Read())
{
result.HasOutput = true;
if (currentRow++ >= MAX_RESULTS)
{
results.Truncated = true;
results.MaxResults = MAX_RESULTS;
break;
}
var row = new List<object>();
resultSet.Rows.Add(row);
for (int i = 0; i < reader.FieldCount; i++)
{
object col = reader.GetValue(i);
if (col is DateTime)
{
var date = (DateTime)col;
col = date.ToJavascriptTime();
}
row.Add(col);
}
}
if (results.Truncated)
{
// next result would force ado.net to fast forward
// through the result set, which is way too slow
break;
}
if (reader.RecordsAffected >= 0)
{
messages.AppendFormat("({0} row(s) affected)\n\n", reader.RecordsAffected);
}
messages.AppendFormat("({0} row(s) affected)\n\n", resultSet.Rows.Count);
}
} while (reader.NextResult());
command.Cancel();
}
results.ExecutionPlan = plan.PlanXml;
}