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


C# SqlConnection.Delete方法代码示例

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


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

示例1: RemoveCustomer

 public void RemoveCustomer(Customer customer)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Delete(CustomerTableName, new KeyValuePair<string, object>("客户号", customer.客户号));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:8,代码来源:ClientInfoManager.cs

示例2: Dapper

        private static void Dapper(int eachCount)
        {
            GC.Collect();//回收资源
            System.Threading.Thread.Sleep(2000);//休息2秒

            //正试比拼
            PerHelper.Execute(eachCount, "Dapper", () =>
            {
                using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
                {
                    var delList = GetDeleteList();
                    var list = conn.Delete(delList);
                }
            });
        }
开发者ID:sunkaixuan,项目名称:SqlSugar,代码行数:15,代码来源:DeleteArray.cs

示例3: Main

        static void Main()
        {
            try
            {
                var connection = new SqlConnection(@"Server=localhost\sqlexpress;Database=ExperimentalStuff;Trusted_Connection=true;");

                var id = new Guid("DB44BD6A-532C-4F9A-A9A0-CE32C193F467");
                var grandParent = new GrandParent
                {
                    Id = id,
                    Name = "grandparent",
                };

                Builder<Parent>.CreateListOfSize(3).Build()
                    .ToList().ForEach(grandParent.AddParent);

                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    connection.Delete<GrandParent>(new { grandParent.Id }, transaction);
                    var insert = connection.Insert(grandParent, transaction);
                    Console.WriteLine(insert);
                    transaction.Commit();
                }
                connection.Close();

                Print(connection, grandParent.Id);
                //connection.Delete<GrandParent>(new { grandParent.Id });

                connection.Dispose();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            finally
            {
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
开发者ID:brettveenstra,项目名称:ExampleCode,代码行数:41,代码来源:Program.cs

示例4: CustomerCRUD

        /// <summary>
        /// Customers the CRUD.
        /// </summary>
        /// <param name="sqlconn">The sqlconn.</param>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        private static void CustomerCRUD(SqlConnection sqlconn)
        {
            var customer = new Customers
            {
                CustomerID = "8273",
                CompanyName = "Newcompanyname",
                ContactName = "ccc",
                Address = "asdcasdws",
                ContactTitle = "asdf",
                City = "kuna",
                Country = "china",
                Fax = "23",
                Phone = "231",
                PostalCode = "234",
                Region = "asia"
            };

            string insertflag = sqlconn.Insert<Customers>(customer);

            //update it
            var myCustomer = sqlconn.Get<Customers>(customer.CustomerID);
            myCustomer.ContactName = "updated name";

            sqlconn.Update<Customers>(myCustomer);

            //delete
            sqlconn.Delete<Customers>(customer);
        }
开发者ID:megadotnet,项目名称:DotNetDataAccessPerformanceProfiler,代码行数:33,代码来源:DapperExtentsionsPerformanceTest.cs

示例5: RemoveRoleFromUser

        public bool RemoveRoleFromUser(int roleId, int userId)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                var recordsAffected =
                    conn.Delete<UserRole>(new Dictionary<string, object>()
                    {
                        {"Id", userId},
                        {"RoleId", roleId}
                    });

                return recordsAffected.Equals(1);
            }
        }
开发者ID:grantcolley,项目名称:authorisationmanager,代码行数:14,代码来源:AuthorisationManagerData.cs

示例6: RemoveRoleFromRole

        public bool RemoveRoleFromRole(int roleId, int parentId)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                var recordsAffected =
                    conn.Delete<RoleRole>(new Dictionary<string, object>()
                    {
                        {"RoleId", roleId},
                        {"ParentRoleId", parentId}
                    });

                return recordsAffected.Equals(1);
            }
        }
开发者ID:grantcolley,项目名称:authorisationmanager,代码行数:14,代码来源:AuthorisationManagerData.cs

示例7: RemoveActivityFromRole

        public bool RemoveActivityFromRole(int activityId, int roleId)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                var recordsAffected =
                    conn.Delete<RoleActivity>(new Dictionary<string, object>()
                    {
                        {"ActivityId", activityId},
                        {"RoleId", roleId}
                    });

                return recordsAffected.Equals(1);
            }
        }
开发者ID:grantcolley,项目名称:authorisationmanager,代码行数:14,代码来源:AuthorisationManagerData.cs

示例8: delete_offer_deletes_equipment_offer_descendents

        public void delete_offer_deletes_equipment_offer_descendents()
        {
            var offerGuid = Guid.NewGuid();
            var equipmentOfferGuid = Guid.NewGuid();
            var offer = new OfferDto
            {
                OfferGuid = offerGuid,
                Equipment = new List<EquipmentOfferTrnDao>
                {
                    new EquipmentOfferTrnDao
                    {
                        EquipmentOfferGuid = equipmentOfferGuid,
                        OfferGuid = offerGuid,
                        EquipmentOptions = new List<EquipmentOptionTrnDao>
                        {
                            new EquipmentOptionTrnDao
                            {
                                EquipmentOptionTrnGuid = Guid.NewGuid(),
                                EquipmentOfferGuid = equipmentOfferGuid,
                                Quantity = 23
                            }
                        }
                    }
                },
                OfferReference = "Test offer",
                OpportunityGuid = Guid.NewGuid()
            };

            var logger = new MockSimpleSaveLogger();
            SimpleSaveExtensions.Logger = logger;
            
            try
            {
                using (IDbConnection connection = new SqlConnection())
                {
                    connection.Delete(offer);
                }
            }
            catch (InvalidOperationException)
            {
                //  Don't care
            }

            var scripts = logger.Scripts;
            Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts.");

            var sql = scripts[0].Buffer.ToString();

            var deleteFromEquipmentOptionIndex = sql.IndexOf("DELETE FROM [opp].[EQUIPMENT_OPTION_TRN]");
            Assert.IsTrue(deleteFromEquipmentOptionIndex >= 0, "No delete from [opp].[EQUIPMENT_OPTION_TRN]");

            var deleteFromEquipmentOfferIndex = sql.IndexOf("DELETE FROM [opp].[EQUIPMENT_OFFER_TRN]");
            Assert.IsTrue(deleteFromEquipmentOfferIndex >= 0, "No delete from [opp].[EQUIPMENT_OFFER_TRN]");

            var deleteFromOfferIndex = sql.IndexOf("DELETE FROM [opp].[OFFER_TRN]");
            Assert.IsTrue(deleteFromOfferIndex >= 0, "No delete from [opp].[OFFER_TRN]");

            Assert.IsTrue(
                deleteFromEquipmentOptionIndex < deleteFromEquipmentOfferIndex,
                "Delete from [opp].[EQUIPMENT_OPTION_TRN] should appear before delete from [opp].[EQUIPMENT_OFFER_TRN]");

            Assert.IsTrue(
                deleteFromEquipmentOfferIndex < deleteFromOfferIndex,
                "Delete from [opp].[EQUIPMENT_OFFER_TRN] should appear before delete from [opp].[OFFER_TRN]");
        }
开发者ID:Paymentsense,项目名称:Dapper.SimpleSave,代码行数:65,代码来源:NestedObjectScriptGenerationTests.cs

示例9: RemoveCustomerContact

 public void RemoveCustomerContact(CustomerContact contact)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Delete(CustomerContactTableName, new KeyValuePair<string, object>("姓名", contact.姓名));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:8,代码来源:ClientInfoManager.cs

示例10: RemoveInventor

 public void RemoveInventor(Inventor inventor)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Delete(InventorTableName, new KeyValuePair<string, object>("身份证号", inventor.身份证号));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:8,代码来源:ClientInfoManager.cs

示例11: RemoveApplicant

 public void RemoveApplicant(Applicant applicant)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Delete(ApplicantTableName, new KeyValuePair<string, object>("证件号", applicant.证件号));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:8,代码来源:ClientInfoManager.cs


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