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


C# MySqlConnection.Execute方法代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection.Execute方法的具体用法?C# MySqlConnection.Execute怎么用?C# MySqlConnection.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySql.Data.MySqlClient.MySqlConnection的用法示例。


在下文中一共展示了MySqlConnection.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAccount

 public static void CreateAccount(string accountName, string friendlyName, string adminPassword, string adminEmail, int planType)
 {
     using (var ts = new TransactionScope())
     {
         using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
         {
             string salt = Guid.NewGuid().ToString();
             sqlConnection.Open();
             sqlConnection.Execute(@"insert into Account(Name,FriendlyName,IsActive,PlanType) values (@Name,@FriendlyName,@IsActive,@PlanType)", new { Name = accountName, FriendlyName = friendlyName, IsActive = true, PlanType = planType });
             sqlConnection.Execute(@"insert into User(Username,Account,Password,Salt,IsActive,IsAdmin,Email) values (@Username,@Account,@Password,@Salt,@IsActive,@IsAdmin,@Email)", new { Username = "administrator", Account = accountName, Password = UtilityHelper.HashPassword(adminPassword, salt), Salt = salt, IsActive = true, IsAdmin = true, Email = adminEmail });
         }
         ts.Complete();
     }
 }
开发者ID:yatendra,项目名称:saasapp,代码行数:14,代码来源:AccountBL.cs

示例2: RunBeforeAnyTests

        public void RunBeforeAnyTests()
        {
            using (var mySqlConnection = new MySqlConnection("Server=localhost;Port=3306;uid=root;password=password!"))
            {
                mySqlConnection.Execute(string.Format("CREATE DATABASE IF NOT EXISTS `{0}`", DatabaseName));
            }

            Container = new Castle.Windsor.WindsorContainer();

            DapperConfiguration
                .Use()
                .UseClassMapper(typeof(AutoClassMapper<>))
                .UseContainer<ContainerForWindsor>(cfg => cfg.UseExisting(Container))
                .UseSqlDialect(new MySqlDialect())
                .WithDefaultConnectionStringNamed("__DefaultMySql")
                .FromAssembly("Dapper.Extensions.Linq.Test.Entities")
                .FromAssembly("Dapper.Extensions.Linq.Test.Maps")
                .Build();

            var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["__DefaultMySql"].ConnectionString);
            var files = new List<string>
            {
                ReadScriptFile("CreateAnimalTable"),
                ReadScriptFile("CreateFooTable"),
                ReadScriptFile("CreateMultikeyTable"),
                ReadScriptFile("CreatePersonTable"),
                ReadScriptFile("CreateCarTable"),
                ReadScriptFile("CreatePhoneTable")
            };

            foreach (var setupFile in files)
            {
                connection.Execute(setupFile);
            }
        }
开发者ID:FlowWithCaptainJack,项目名称:Dapper.Extensions.Linq,代码行数:35,代码来源:MySql.cs

示例3: CreateOfficeDepartment

        public void CreateOfficeDepartment(DepartmentToUser departmentToUser)
        {
            using (MySqlConnection db = new MySqlConnection(ConfigurationValues.GroveHillConnection))
            {
                departmentToUser.UniqueID = Guid.NewGuid().ToString();

                try
                {
                    const string query = "insert into officenames(UniqueID,Name,Department)"
                        + " values(@UniqueID,@Name,@Department)";
                    int rowsAffectd = db.Execute(query, new
                    {
                        @UniqueID = departmentToUser.UniqueID,
                        @Name = departmentToUser.Name,
                        @Department = departmentToUser.Department
                    });
                    int r = 5;
                }
                catch (Exception er)
                {
                    string s1 = er.ToString();
                    //Log.LogMessage(er.ToString());
                }
            }
        }
开发者ID:connecticutortho,项目名称:ct-ortho-repositories4,代码行数:25,代码来源:OfficeDepartments.cs

示例4: AddBlock

        public void AddBlock(IShare share)
        {
            try
            {
                if (!IsEnabled)
                    return;

                using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
                {
                    connection.Execute(
                        @"INSERT INTO Block(Height, BlockHash, TxHash, Amount, CreatedAt) VALUES (@height, @blockHash, @txHash, @amount, @createdAt)",
                        new
                        {
                            height = share.Block.Height,
                            blockHash = share.BlockHash.ToHexString(),
                            txHash = share.Block.Tx.First(),
                            amount = (decimal)share.GenerationTransaction.TotalAmount,
                            createdAt = share.Block.Time.UnixTimestampToDateTime()
                        });
                }
            }
            catch (Exception e)
            {
                _logger.Error("An exception occured while adding block; {0:l}", e.Message);
            }
        }
开发者ID:carloslozano,项目名称:CoiniumServ,代码行数:26,代码来源:HybridStorage.Blocks.cs

示例5: CreateDatabaseIfNeeded

        private void CreateDatabaseIfNeeded()
        {
            using (var conn = new MySqlConnection(_connectionString))
                conn.Execute($"CREATE DATABASE IF NOT EXISTS {_databaseName}");

            using (var conn = OpenConnection())
            {
                if (!DoesTableExists(conn, "EndpointConfig"))
                    CreateEndpointConfig(conn);
                if (!DoesColumnExists(conn, "EndpointConfig", "Tags"))
                    CreateColumn(conn, "EndpointConfig", "Tags", "varchar(4096)");
                if (!DoesColumnExists(conn, "EndpointConfig", "Password"))
                    CreateColumn(conn, "EndpointConfig", "Password", "varchar(64)");
                var date = DateTime.UtcNow;
                if (!DoesColumnExists(conn, "EndpointConfig", "RegisteredOnUtc"))
                    CreateColumnAndSetValue(conn, "EndpointConfig", "RegisteredOnUtc", "datetime not null", date);
                if (!DoesColumnExists(conn, "EndpointConfig", "RegistrationUpdatedOnUtc"))
                    CreateColumnAndSetValue(conn, "EndpointConfig", "RegistrationUpdatedOnUtc", "datetime not null", date);
                if (!DoesColumnExists(conn, "EndpointConfig", "MonitorTag"))
                    CreateColumn(conn, "EndpointConfig", "MonitorTag", "varchar(1024) default 'default'");
                if (!DoesTableExists(conn, "EndpointStats"))
                    CreateEndpointStats(conn);
                if (!DoesTableExists(conn, "HealthMonitorTypes"))
                    CreateHealthMonitorTypesTable(conn);
                if (!DoesIndexExists(conn, "EndpointStats", "EndpointStats_EndpointIdCheckTimeUtc_idx"))
                    CreateEndpointStatsIndex(conn);
                if (!DoesIndexExists(conn, "EndpointConfig", "EndpointConfig_MonitorTag_idx"))
                    CreateMonitorTagIndex(conn);
                if (!DoesIndexExists(conn, "EndpointConfig", "EndpointConfig_MonitorType_idx"))
                    CreateMonitorTypeIndex(conn);
            }
        }
开发者ID:wongatech,项目名称:HealthMonitoring,代码行数:32,代码来源:MySqlDatabase.cs

示例6: UpdateBlock

        public void UpdateBlock(IPersistedBlock block)
        {
            try
            {
                if (!IsEnabled)
                    return;

                using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
                {
                    connection.Execute(
                        @"UPDATE Block SET Orphaned = @orphaned, Confirmed = @confirmed, Accounted = @accounted, Reward = @reward WHERE Height = @height",
                        new
                        {
                            orphaned = block.Status == BlockStatus.Orphaned,
                            confirmed = block.Status == BlockStatus.Confirmed,
                            accounted = block.Accounted,
                            reward = block.Reward,
                            height = block.Height
                        });
                }
            }
            catch (Exception e)
            {
                _logger.Error("An exception occured while updating block; {0:l}", e.Message);
            }
        }
开发者ID:carloslozano,项目名称:CoiniumServ,代码行数:26,代码来源:HybridStorage.Blocks.cs

示例7: AddPayment

        public void AddPayment(IPayment payment)
        {
            try
            {
                if (!IsEnabled)
                    return;

                using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
                {
                    connection.Execute(
                        @"INSERT INTO Payment(Block, AccountId, Amount, CreatedAt) VALUES(@blockId, @accountId, @amount, @createdAt)",
                        new
                        {
                            blockId = payment.BlockId,
                            accountId = payment.AccountId,
                            amount = payment.Amount,
                            createdAt = DateTime.Now
                        });
                }
            }
            catch (Exception e)
            {
                _logger.Error("An exception occured while committing payment; {0:l}", e.Message);
            }
        }
开发者ID:carloslozano,项目名称:CoiniumServ,代码行数:25,代码来源:HybridStorage.Payments.cs

示例8: GetValidatedUser

 public static DataModel.User GetValidatedUser(string username, string password, string account)
 {
     using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
     {
         sqlConnection.Open();
         DataModel.User userObj = sqlConnection.Query<DataModel.User>("Select * from User where [email protected] and [email protected]", new { Username = username, Account = account }).FirstOrDefault();
         if (userObj != null)
         {
             if (string.IsNullOrEmpty(userObj.Salt))
             {
                 if (password.Equals(userObj.Password))
                 {
                     string salt = Guid.NewGuid().ToString();
                     sqlConnection.Execute(@"update User set [email protected], [email protected] where [email protected] and [email protected]", new { Salt = salt, Password = UtilityHelper.HashPassword(userObj.Password, salt), Username = username, Account = account });
                     return userObj;
                 }
             }
             else
             {
                 password=UtilityHelper.HashPassword(password,userObj.Salt);
                 if (password.Equals(userObj.Password))
                 {
                     return userObj;
                 }
             }
         }
     }
     return null;
 }
开发者ID:yatendra,项目名称:saasapp,代码行数:29,代码来源:UserBL.cs

示例9: Activate

 public void Activate(Promocion p)
 {
     using (MySqlConnection conn = new MySqlConnection(Constants.QueryConn))
     {
         try
         {
             conn.Open();
             var platos = GetPlatosByPromo(p);
             PlatoDao platoDao = new PlatoDao();
             foreach (var pl in platos)
             {
                 var plato = platoDao.GetOne(pl.Plato_Id);
                 if (plato.Estado != "DISPONIBLE")
                 {
                     throw new DataException("No se puede marcar como DISPONIBLE una promoción que contiene platos NO DISPONIBLES");
                 }
             }
             if (conn.Execute(Constants.ActivatePromo, p, null, null, CommandType.Text) == -1)
             {
                 throw new DataException("No se actualizó la promoción como DISPONIBLE");
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
     }
 }
开发者ID:jgyonzo,项目名称:Restaurant-BD2,代码行数:32,代码来源:PromocionesDao.cs

示例10: InsertSiteCatUrlTableAusYp

        //***************************************************Australia***************************************
        //Australia Yellow Pages Category

        #region --For InsertSiteCatUrlTableAusYp
        public int InsertSiteCatUrlTableAusYp(string SiteName, string SiteUrl, string Category, DateTime CrawlDate, string Status)
        {
            using (MySqlConnection conn = new MySqlConnection(BG_Db_Class.getConnectionString()))
            try
            {
               {
                   if (conn.State != ConnectionState.Open)
                       try
                       {
                           conn.Open();
                       }
                       catch (MySqlException ex)
                       {
                           throw (ex);
                       }

                    int rowAffected = conn.Execute(@"INSERT INTO Bus_Data_AusYPCatUrl(SiteName,Url,Category,date,Status) VALUES(@SiteName,@SiteUrl,@Category,@date,@Status)", new { SiteName = SiteName, SiteUrl = SiteUrl, Category = Category, date = CrawlDate, Status = Status });
                    return rowAffected;
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
            finally
            {
                conn.Close();
            }

        }
开发者ID:sumitglobussoft,项目名称:Instagram-PVA-BOT,代码行数:34,代码来源:Cls_BGSiteUrlManagement.cs

示例11: DeleteUser

 public static void DeleteUser(string account, string username)
 {
     using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
     {
         sqlConnection.Open();
         sqlConnection.Execute(@"update User set IsActive=false where [email protected] and [email protected]", new { Username = username, Account = account });
     }
 }
开发者ID:yatendra,项目名称:saasapp,代码行数:8,代码来源:UserBL.cs

示例12: CreateUser

 public static void CreateUser(string username, string accountName, string password, string email, bool? isAdmin)
 {
     using (MySqlConnection sqlConnection = new MySqlConnection(UtilityHelper.GetConnectionString()))
     {
         string salt = Guid.NewGuid().ToString();
         sqlConnection.Open();
         sqlConnection.Execute(@"insert into User(Username,Account,Password,Salt,IsActive,IsAdmin,Email) values (@Username,@Account,@Password,@Salt,@IsActive,@IsAdmin,@Email)", new { Username = username, Account = accountName, Password = UtilityHelper.HashPassword(password, salt), Salt = salt, IsActive = true, IsAdmin = isAdmin, Email = email });
     }
 }
开发者ID:yatendra,项目名称:saasapp,代码行数:9,代码来源:UserBL.cs

示例13: DeleteCoord

        public bool DeleteCoord(int id)
        {
            using (var cn = new MySqlConnection(_connectionString))
            {
                const string sql = "DELETE FROM `geopoints` WHERE `ID`[email protected];";

                return cn.Execute(sql, new {ID = id}) > 0;
            }
        }
开发者ID:ThinkBiscuit,项目名称:GeoTest,代码行数:9,代码来源:Repositories.cs

示例14: DeleteAllPlatos

 public int DeleteAllPlatos(Promocion p, MySqlConnection conn, MySqlTransaction trans)
 {
     try
     {
         return conn.Execute(Constants.DeletePlatosByPromo, p, trans, null, CommandType.Text);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:jgyonzo,项目名称:Restaurant-BD2,代码行数:11,代码来源:PromocionesDao.cs

示例15: DeleteImage

        /// <summary>
        /// Deletes an image from the DB
        /// </summary>
        /// <param name="imageId">The Id of the image to delete</param>
        public void DeleteImage(int imageId)
        {
            using (var connection = new MySqlConnection(Common.ConnectionString))
            {
                connection.Open();

                connection.Execute("osae_sp_image_delete",
                    new { pimage_id = imageId },
                    commandType: CommandType.StoredProcedure);
            }
        }
开发者ID:matthewste,项目名称:Open-Source-Automation,代码行数:15,代码来源:OSAEImageManager.cs


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