本文整理汇总了C#中System.Data.Common.DbCommand类的典型用法代码示例。如果您正苦于以下问题:C# DbCommand类的具体用法?C# DbCommand怎么用?C# DbCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbCommand类属于System.Data.Common命名空间,在下文中一共展示了DbCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TableManager
internal TableManager(string tableName)
{
try
{
_da = TableManager._DbProviderFactory.CreateDataAdapter();
_cmd = TableManager._DbProviderFactory.CreateCommand();
DbCommandBuilder cb =
TableManager._DbProviderFactory.CreateCommandBuilder();
cb.QuotePrefix = "[";
cb.QuoteSuffix = "]";
_cmd.Connection = TableManager.Connection;
cb.ConflictOption = ConflictOption.OverwriteChanges;
cb.DataAdapter = _da;
_dt = new DataTable();
_temp = new DataTable();
_dt.TableName = _temp.TableName = tableName;
_cmd.CommandText = "Select * from " + Table.TableName;
_da.SelectCommand = _cmd;
_da.InsertCommand = cb.GetInsertCommand();
_da.DeleteCommand = cb.GetDeleteCommand();
_da.UpdateCommand = cb.GetUpdateCommand();
Recharge("1 = 2");
}
catch { GlobalErrorCode = 13; }
if (GlobalErrorCode == 13)
MessageBox.Show("ОШИБКА");
}
示例2: ExecuteMultipleTableSelectCommand
/// <summary>
/// Returns a DataSet (best used for multiple tables in the result set)
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
/// <see cref=">http://msdn.microsoft.com/en-us/library/fks3666w%28VS.80%29.aspx" />
public static DataSet ExecuteMultipleTableSelectCommand(DbCommand command)
{
using (command)
{
var factory = DbProviderFactories.GetFactory(DataBaseConfigs.DbProviderName);
using (var adapter = factory.CreateDataAdapter())
{
if (adapter == null) return null;
adapter.SelectCommand = command;
using (var ds = new DataSet())
{
try
{
adapter.Fill(ds);
}
catch (Exception ex)
{
Utilities.LogError(ex);
return null;
}
command.Connection.Close();
return ds;
}
}
}
}
示例3: InitializeParameters
private void InitializeParameters(DbCommand command)
{
if (!command.Parameters.Contains("@CD_CLIFOR"))
{
db.AddInParameter(command, "@CD_CLIFOR", DbType.String);
}
}
示例4: ExecuteSelectCommand
// executes a command and returns the results as a DataTable object
public static DataTable ExecuteSelectCommand(DbCommand command)
{
// The DataTable to be returned
DataTable table;
// Execute the command making sure the connection gets closed in the end
try
{
// Open the data connection
command.Connection.Open();
// Execute the command and save the results in a DataTable
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
// Close the reader
reader.Close();
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw;
}
finally
{
// Close the connection
command.Connection.Close();
}
return table;
}
示例5: SqlDataSourceStatusEventArgs
public SqlDataSourceStatusEventArgs (DbCommand command, int rowsAffected, Exception exception)
{
this.command = command;
this.rowsAffected = rowsAffected;
this.exception = exception;
this.exceptionHandled = false;
}
示例6: PrepareCommand
private static void PrepareCommand(
DbCommand command,
DbConnection connection,
DbTransaction transaction,
CommandType commandType,
string commandText,
DbParameter[] commandParameters)
{
if (command == null) throw new ArgumentNullException("command");
if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText");
command.Connection = connection;
command.CommandText = commandText;
command.CommandType = commandType;
if (transaction != null)
{
if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
command.Transaction = transaction;
}
if (commandParameters != null)
{
AttachParameters(command, commandParameters);
}
return;
}
示例7: GlimpseDbDataReader
public GlimpseDbDataReader(DbDataReader dataReader, DbCommand command, Guid connectionId, Guid commandId)
{
InnerDataReader = dataReader;
InnerCommand = command;
ConnectionId = connectionId;
CommandId = commandId;
}
示例8: CreateParameterCopy
private static IDataParameter[] CreateParameterCopy(DbCommand command)
{
IDataParameterCollection parameters = command.Parameters;
IDataParameter[] array = new IDataParameter[parameters.Count];
parameters.CopyTo(array, 0);
return CachingMechanism.CloneParameters(array);
}
示例9: CreateAndCacheDbCommandParameters
public void CreateAndCacheDbCommandParameters(string sqlCommandText,
DbCommand command,
string[] paramNames,
DbType[] paramDbTypes,
object[] paramValues)
{
lock (lockObject)
{
if (this.ParameterCache.IsCache(sqlCommandText))
{
this.ParameterCache.AddParametersFromCache(sqlCommandText, command, paramDbTypes, paramValues);
}
else
{
if (this.ParameterCache.IsCache(sqlCommandText))
{
this.ParameterCache.AddParametersFromCache(sqlCommandText, command, paramDbTypes, paramValues);
}
else
{
this.ParameterCache.CreateAndCacheParameters(sqlCommandText, command, paramNames, paramDbTypes, paramValues);
}
}
}
}
示例10: setupDbCommand
private void setupDbCommand( DbCommand dbCmd, DatabaseInfo databaseInfo )
{
dbCmd.CommandText = sproc;
dbCmd.CommandType = CommandType.StoredProcedure;
foreach( var p in parameters )
dbCmd.Parameters.Add( p.GetAdoDotNetParameter( databaseInfo ) );
}
示例11: AddParametersFromCache
protected virtual void AddParametersFromCache(DbCommand command, Database database)
{
foreach (IDataParameter parameter in this.cache.GetCachedParameterSet(database.ConnectionString, command))
{
command.Parameters.Add(parameter);
}
}
示例12: LoggingCommandWrapper
public LoggingCommandWrapper(DbCommand dbCommand, ILogger logger)
{
Contract.Requires(dbCommand != null, nameof(dbCommand) + " is null.");
Contract.Requires(logger != null, nameof(logger) + " is null.");
_WrappedDbCommand = dbCommand;
_Logger = logger;
}
示例13: GetReportData
private DataTable GetReportData(DbCommand cmd, ArrayList parameterList)
{
db.AddInParameter(cmd, "p_patchDateS", DbType.String, parameterList[0]);
db.AddInParameter(cmd, "p_patchDateE", DbType.String, parameterList[1]);
db.AddInParameter(cmd, "p_signDate_S", DbType.String, parameterList[2]);
db.AddInParameter(cmd, "p_signDate_E", DbType.String, parameterList[3]);
db.AddInParameter(cmd, "p_acDate_S", DbType.String, parameterList[4]);
db.AddInParameter(cmd, "p_acDate_E", DbType.String, parameterList[5]);
db.AddInParameter(cmd, "p_groupS", DbType.String, parameterList[6]);
db.AddInParameter(cmd, "p_groupE", DbType.String, parameterList[7]);
db.AddInParameter(cmd, "p_payRfno", DbType.String, parameterList[8]);
db.AddInParameter(cmd, "p_rfno", DbType.String, parameterList[9]);
db.AddInParameter(cmd, "p_profit_S", DbType.String, parameterList[10]);
db.AddInParameter(cmd, "p_profit_E", DbType.String, parameterList[11]);
db.AddInParameter(cmd, "p_store_S", DbType.String, parameterList[12]);
db.AddInParameter(cmd, "p_store_E", DbType.String, parameterList[13]);
db.AddInParameter(cmd, "p_acUID", DbType.String, parameterList[14]);
db.AddInParameter(cmd, "p_rootNo", DbType.String, parameterList[15]);
db.AddInParameter(cmd, "p_item", DbType.String, parameterList[16]);
db.AddInParameter(cmd, "p_periodS", DbType.String, parameterList[17]);
db.AddInParameter(cmd, "p_periodE", DbType.String, parameterList[18]);
db.AddInParameter(cmd, "p_checkReasonS", DbType.String, parameterList[19]);
db.AddInParameter(cmd, "p_checkReasonE", DbType.String, parameterList[20]);
db.AddInParameter(cmd, "p_descTypeS", DbType.String, parameterList[21]);
db.AddInParameter(cmd, "p_descTypeE", DbType.String, parameterList[22]);
db.AddInParameter(cmd, "p_diffTimes", DbType.String, parameterList[23]);
db.AddInParameter(cmd, "p_diffAmount", DbType.String, parameterList[24]);
db.AddInParameter(cmd, "p_diffSource", DbType.String, parameterList[25]);
db.AddInParameter(cmd, "p_op1", DbType.String, ConvertOperator(parameterList[26].ToString()));
db.AddInParameter(cmd, "p_op2", DbType.String, ConvertOperator(parameterList[27].ToString()));
DataTable dt = db.ExecuteDataSet(cmd).Tables[0];
return dt;
}
示例14: GetSqlFromDbCommand
public static string GetSqlFromDbCommand(DbCommand dbCommand)
{
string strSql = dbCommand.CommandText;
foreach (DbParameter dp in dbCommand.Parameters)
{
string strReplace = string.Empty;
if (dp.Value == DBNull.Value)
{
strReplace = "NULL";
}
else if (dp.DbType == DbType.Int32)
{
strReplace = string.Format("{0}", dp.Value);
}
else
{
strReplace = string.Format("'{0}'", dp.Value);
}
strSql = strSql.Replace(PARAMETER_NAME_PREFIX_AT + dp.ParameterName, strReplace);
strSql = strSql.Replace(PARAMETER_NAME_PREFIX_COLON + dp.ParameterName, strReplace);
}
return strSql;
}
示例15: ExecuteScalar
// execute a select command and return a single result as a string
public static string ExecuteScalar(DbCommand command)
{
// The value to be returned
string value = "";
// Execute the command making sure the connection gets closed in the end
try
{
// Open the connection of the command
command.Connection.Open();
// Execute the command and get the number of affected rows
value = command.ExecuteScalar().ToString();
}
catch (Exception ex)
{
// Log eventual errors and rethrow them
//Utilities.LogError(ex);
throw ex;
}
finally
{
// Close the connection
command.Connection.Close();
}
// return the result
return value;
}