本文整理汇总了C#中Finisar.SQLite.SQLiteCommand.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteCommand.ExecuteScalar方法的具体用法?C# SQLiteCommand.ExecuteScalar怎么用?C# SQLiteCommand.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Finisar.SQLite.SQLiteCommand
的用法示例。
在下文中一共展示了SQLiteCommand.ExecuteScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScalar
/// <summary>
/// Execute a SQLiteCommand (that returns a 1x1 resultset) against the specified SQLiteTransaction
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(trans, CommandType.Text, "Select count(Order) from TableTransaction where ProdId=?", new SQLiteParameter("@prodid", 24));
/// </remarks>
/// <param name="transaction">A valid SQLiteTransaction</param>
/// <param name="commandType">The CommandType (TableDirect, Text)</param>
/// <param name="commandText">The T-SQL command</param>
/// <param name="commandParameters">An array of SQLiteParamters used to execute the command</param>
/// <returns>An object containing the value in the 1x1 resultset generated by the command</returns>
public static object ExecuteScalar(SQLiteTransaction transaction, CommandType commandType, string commandText, params SQLiteParameter[] commandParameters)
{
if( transaction == null ) throw new ArgumentNullException( "transaction" );
if( transaction != null && transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" );
// Create a command and prepare it for execution
SQLiteCommand cmd = new SQLiteCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, (SQLiteConnection)transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
// Execute the command & return the results
object retval = cmd.ExecuteScalar();
// Detach the SQLiteParameters from the command object, so they can be used again
cmd.Parameters.Clear();
return retval;
}
示例2: OnRowUpdated
// If it's an Insert we fetch the @@Identity value and stuff it in the proper column
protected void OnRowUpdated(object sender, RowUpdatedEventArgs e)
{
try
{
if(e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
{
TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();
string[] identityCols = this.GetAutoKeyColumns().Split(';');
SQLiteCommand cmd = new SQLiteCommand();
foreach(string col in identityCols)
{
cmd.CommandText = "SELECT last_insert_rowid()";
// We make sure we enlist in the ongoing transaction, otherwise, we
// would most likely deadlock
txMgr.Enlist(cmd, this);
object o = cmd.ExecuteScalar(); // Get the Identity Value
txMgr.DeEnlist(cmd, this);
if(o != null)
{
e.Row[col] = o;
}
}
e.Row.AcceptChanges();
}
}
catch {}
}