当前位置: 首页>>代码示例>>C#>>正文


C# DbCommand类代码示例

本文整理汇总了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();
     }
 }
开发者ID:hackersdelight,项目名称:Loop,代码行数:29,代码来源:UserActions.cs

示例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);
 }
开发者ID:jiangxianfu,项目名称:MiniORM,代码行数:7,代码来源:Database.cs

示例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;
 }
开发者ID:JackFong,项目名称:QuantumCode.SDAL,代码行数:7,代码来源:MySqlDatabase.cs

示例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();
     }
 }
开发者ID:hackersdelight,项目名称:Loop,代码行数:29,代码来源:UserActions.cs

示例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();
     }
 }
开发者ID:hackersdelight,项目名称:Loop,代码行数:25,代码来源:RiskActions.cs

示例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;
 }
开发者ID:ChristophWurst,项目名称:UFO,代码行数:7,代码来源:Database.cs

示例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);
        }
开发者ID:iainlane,项目名称:f-spot,代码行数:26,代码来源:RetroactiveRoll.cs

示例8: BuilderData

 public BuilderData(DbCommand command, string tableName)
 {
     TableName = tableName;
     Command = command;
     Columns = new List<BuilderColumn>();
     Where = new List<BuilderColumn>();
     WhereString = new List<string>();
 }
开发者ID:kkbac,项目名称:kkbac.tools,代码行数:8,代码来源:BuilderData.cs

示例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();
        }
开发者ID:AlexJCarstensen,项目名称:ProgrammingWithMosh,代码行数:8,代码来源:Program.cs

示例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);
 }
开发者ID:JackFong,项目名称:QuantumCode.SDAL,代码行数:8,代码来源:MySqlDatabase.cs

示例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;
 }
开发者ID:mono,项目名称:momareports,代码行数:8,代码来源:BaseData.cs

示例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;
        }
开发者ID:hhahh2011,项目名称:CH.Gps,代码行数:9,代码来源:DBHelper.cs

示例13: EasylinkCommand

        internal EasylinkCommand(DbCommand command, string schemaName)
        {
            _command = command;

            _schemaName = schemaName;

            Sqls = new List<string>();

        }
开发者ID:EasyExpress,项目名称:Easylink,代码行数:9,代码来源:EasylinkCommand.cs

示例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];
         }
 }
开发者ID:jiangxianfu,项目名称:MiniORM,代码行数:10,代码来源:Database.cs

示例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);
 }
开发者ID:ChristophWurst,项目名称:UFO,代码行数:10,代码来源:Database.cs


注:本文中的DbCommand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。