本文整理汇总了C#中DbCommand类的典型用法代码示例。如果您正苦于以下问题:C# DbCommand类的具体用法?C# DbCommand怎么用?C# DbCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbCommand类属于命名空间,在下文中一共展示了DbCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteUser
public void DeleteUser(int id)
{
try
{
connection.OpenConnection();
connection.BeginTransaction();
DbCommand command = new DbCommand("DELETE FROM Users WHERE Id = @id;");
command.Parameters = new SqlParameter[1];
command.Parameters[0] = new SqlParameter("id", id);
command.Type = DbCommand.DbCommandType.DELETE;
connection.ExecNonQuery(command);
if (UserCollection != null)
{
UserCollection.Remove(UserCollection.Find(x => x.Id == id));
}
ReassignTasks(id);
connection.CommitTransaction();
}
catch (Exception e)
{
connection.RollbackTransaction();
Logger.Instance.WriteToLog(e.StackTrace);
throw;
}
finally
{
connection.CloseConnection();
}
}
示例2: AddParameter
public void AddParameter(DbCommand command, string name, object value)
{
DbParameter param = command.CreateParameter();
param.ParameterName = name;
param.Value = value ?? (object)DBNull.Value;
command.Parameters.Add(param);
}
示例3: SameNumberOfParametersAndValues
protected override bool SameNumberOfParametersAndValues(DbCommand command, object[] values)
{
int returnParameterCount = 0;
int numberOfParametersToStoredProcedure = command.Parameters.Count - returnParameterCount;
int numberOfValuesProvidedForStoredProcedure = values.Length;
return numberOfParametersToStoredProcedure == numberOfValuesProvidedForStoredProcedure;
}
示例4: AddUser
public void AddUser(IUser user)
{
try
{
connection.OpenConnection();
DbCommand command = new DbCommand("INSERT INTO Users (Login, Password, Name, Surname, Email, IsActive, UserType) VALUES (@login, @password, @name, @surname, @email, @isactive, @usertype);");
command.Parameters = new SqlParameter[7];
command.Parameters[0] = new SqlParameter("login", user.Login);
command.Parameters[1] = new SqlParameter("password", user.Password);
command.Parameters[2] = new SqlParameter("name", user.Name);
command.Parameters[3] = new SqlParameter("surname", user.Surname);
command.Parameters[4] = new SqlParameter("email", user.Email);
command.Parameters[5] = new SqlParameter("isactive", user.IsActive.ToString());
command.Parameters[6] = new SqlParameter("usertype", (int)user.UserType);
command.Type = DbCommand.DbCommandType.INSERT;
connection.ExecNonQuery(command);
//collection doesn't contain user Id here;
UserCollection = null;
}
catch (Exception e)
{
Logger.Instance.WriteToLog(e.StackTrace);
throw;
}
finally
{
connection.CloseConnection();
}
}
示例5: DeleteRisk
public void DeleteRisk(int id)
{
try
{
connection.OpenConnection();
DbCommand command = new DbCommand("DELETE FROM Risks WHERE Id = @id;");
command.Parameters = new SqlParameter[1];
command.Parameters[0] = new SqlParameter("id", id);
command.Type = DbCommand.DbCommandType.DELETE;
connection.ExecNonQuery(command);
if (RiskCollection != null)
{
RiskCollection.Remove(RiskCollection.Find(x => x.Id == id));
}
}
catch (Exception e)
{
Logger.Instance.WriteToLog(e.StackTrace);
throw;
}
finally
{
connection.CloseConnection();
}
}
示例6: SetParameter
public void SetParameter(DbCommand cmd, string name, object value)
{
if (!cmd.Parameters.Contains(name)) {
throw new ArgumentException($"Parameter {name} not declared.");
}
cmd.Parameters[name].Value = value;
}
示例7: Run
public void Run(object o, EventArgs e)
{
Photo[] photos = MainWindow.Toplevel.SelectedPhotos ();
if (photos.Length == 0) {
Console.WriteLine ("no photos selected, returning");
return;
}
DateTime import_time = photos[0].Time;
foreach (Photo p in photos)
if (p.Time > import_time)
import_time = p.Time;
RollStore rolls = App.Instance.Database.Rolls;
Roll roll = rolls.Create(import_time);
foreach (Photo p in photos) {
DbCommand cmd = new DbCommand ("UPDATE photos SET roll_id = :roll_id " +
"WHERE id = :id ",
"roll_id", roll.Id,
"id", p.Id);
App.Instance.Database.Database.ExecuteNonQuery (cmd);
p.RollId = roll.Id;
}
Console.WriteLine ("RetroactiveRoll done: " + photos.Length + " photos in roll " + roll.Id);
}
示例8: BuilderData
public BuilderData(DbCommand command, string tableName)
{
TableName = tableName;
Command = command;
Columns = new List<BuilderColumn>();
Where = new List<BuilderColumn>();
WhereString = new List<string>();
}
示例9: Main
static void Main(string[] args)
{
var command = new DbCommand(new OracleConnection("oracle"), "SaveChanges()" );
command.Execute();
var command1 = new DbCommand(new SqlConnection("SQL"), "Clear()" );
command1.Execute();
}
示例10: AddParameter
public override void AddParameter(DbCommand command, string name, DbType dbType, int size,
ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion,
object value)
{
DbParameter parameter = this.CreateParameter(name, dbType, size,
direction, nullable, precision, scale, sourceColumn, sourceVersion, value);
command.Parameters.Add(parameter);
}
示例11: AddParameter
protected static DbParameter AddParameter(DbCommand cmd, string name, object val)
{
DbParameter p = cmd.CreateParameter ();
p.ParameterName = name;
p.Value = val;
cmd.Parameters.Add (p);
return p;
}
示例12: PrepareCommand
private static void PrepareCommand(DbCommand cmd, MySqlConnection conn, CommandType cmdType, string cmdText)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
cmd.CommandType = cmdType;
}
示例13: EasylinkCommand
internal EasylinkCommand(DbCommand command, string schemaName)
{
_command = command;
_schemaName = schemaName;
Sqls = new List<string>();
}
示例14: ExecuteTable
public DataTable ExecuteTable(DbCommand cmd)
{
using (DataSet st = new DataSet())
{
DbDataAdapter ap = CreateDataAdapter();
ap.SelectCommand = cmd;
ap.Fill(st);
return st.Tables[0];
}
}
示例15: DeclareParameter
public int DeclareParameter(DbCommand cmd, string name, DbType type)
{
if (cmd.Parameters.Contains(name)) {
throw new ArgumentException($"Parameter {name} already declared.");
}
DbParameter param = cmd.CreateParameter();
param.ParameterName = name;
param.DbType = type;
return cmd.Parameters.Add(param);
}