• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DbCommand类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DbCommand的典型用法代码示例。如果您正苦于以下问题:C# DbCommand类的具体用法?C# DbCommand怎么用?C# DbCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DbCommand类属于命名空间,在下文中一共展示了DbCommand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: ExecuteDataTableAsList

        /// <summary>
        /// 여러 ResultSet을 반환할 수 있으므로, DataTable의 컬렉션으로 반환합니다.
        /// </summary>
        public override IList<DataTable> ExecuteDataTableAsList(DbCommand cmd, int firstResult, int maxResults,
                                                                params IAdoParameter[] parameters) {
            cmd.ShouldBeInstanceOf<MySqlCommand>("cmd");

            return With.TryFunctionAsync(() => Db.ExecuteDataTableAsListAsync((MySqlCommand)cmd,
                                                                              firstResult,
                                                                              maxResults,
                                                                              parameters)
                                                   .Result,
                                         () => new List<DataTable>());
        }
开发者ID:debop,项目名称:NFramework,代码行数:14,代码来源:MySqlRepositoryImpl.cs


示例17: ExecuteDataSet

        /// <summary>
        /// <paramref name="cmd"/>를 실행하여, 결과를 DataSet으로 반환합니다.
        /// </summary>
        /// <param name="cmd">실행할 <see cref="DbCommand"/> instance.</param>
        /// <param name="firstResult">첫번째 레코드의 인덱스 (0부터 시작)</param>
        /// <param name="maxResults">최대 레코드 수 (0 이면 무시하고, 마지막 레코드까지 가져온다</param>
        /// <param name="parameters">collectio of parameters of Command</param>
        /// <returns>결과 셋이 담긴 DataSet</returns>
        public override DataSet ExecuteDataSet(DbCommand cmd, int firstResult, int maxResults, params IAdoParameter[] parameters) {
            cmd.ShouldNotBeNull("cmd");

            var result = new DataSet();

            var tables = ExecuteDataTableAsList(cmd, firstResult, maxResults, parameters);
            if(tables != null)
                result.Tables.AddRange(tables.ToArray());

            return result;
        }
开发者ID:debop,项目名称:NFramework,代码行数:19,代码来源:MySqlRepositoryImpl.cs


示例18: ExecuteNonQuery

 public int ExecuteNonQuery(DbCommand cmd)
 {
     DbConnection conn = null;
     try {
         conn = this.GetOpenConnection();
         cmd.Connection = conn;
         return cmd.ExecuteNonQuery();
     } finally {
         this.ReleaseConnection(conn);
     }
 }
开发者ID:ChristophWurst,项目名称:UFO,代码行数:11,代码来源:Database.cs


示例19: AddParameter

 protected override void AddParameter(DbCommand command, QueryParameter parameter, object value)
 {
     DbQueryType sqlType = (DbQueryType)parameter.QueryType;
     if (sqlType == null)
         sqlType = (DbQueryType)this.provider.Language.TypeSystem.GetColumnType(parameter.Type);
     var p = ((MySqlCommand)command).Parameters.Add(parameter.Name, ToMySqlDbType(sqlType.SqlDbType), sqlType.Length);
     if (sqlType.Precision != 0)
         p.Precision = (byte)sqlType.Precision;
     if (sqlType.Scale != 0)
         p.Scale = (byte)sqlType.Scale;
     p.Value = value ?? DBNull.Value;
 }
开发者ID:RukaiYu,项目名称:EnterpriseDevelopmentFx,代码行数:12,代码来源:MySqlDbProvider.cs


示例20: ExecuteReader

 public IDataReader ExecuteReader(DbCommand cmd)
 {
     DbConnection conn = null;
     try {
         conn = this.GetOpenConnection();
         cmd.Connection = conn;
         CommandBehavior behavior = this.IsSharedConnection() ? CommandBehavior.Default : CommandBehavior.CloseConnection;
         return cmd.ExecuteReader(behavior);
     } catch {
         ReleaseConnection(conn);
         throw;
     }
 }
开发者ID:ChristophWurst,项目名称:UFO,代码行数:13,代码来源:Database.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DbCompiledModel类代码示例发布时间:2022-05-24
下一篇:
C# DbColumn类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap