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


C# SqlConnection.Update方法代码示例

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


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

示例1: UpdatesWithChangeTracking

		public static void UpdatesWithChangeTracking()
		{
			using (var cn = new SqlConnection(CONNECTION_STRING))
			{
				var contact = cn.Get<IContact>(1);
				Console.WriteLine("Update occurred: {0}", cn.Update(contact));
				
				contact.FirstName = "J.";
				Console.WriteLine("Update occurred: {0}", cn.Update(contact));
			}

			Console.ReadKey();
		}
开发者ID:jonathantower,项目名称:dapper,代码行数:13,代码来源:DapperContrib.cs

示例2: Update

 public bool Update(BuybackResultAbsSale poco)
 {
     using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString))
     {
         return connection.Update(poco);
     }
 }
开发者ID:coderasm,项目名称:ABSBuybackMVCWebAPI,代码行数:7,代码来源:BuybackResultAbsSaleRepository.cs

示例3: RunInsertOrUpdateWithDuplicatePropertyMappings

        private void RunInsertOrUpdateWithDuplicatePropertyMappings(TableB oldObject, TableB newObject)
        {
            try
            {
                SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = false;
                var logger = CreateMockLogger();

                try
                {
                    using (IDbConnection connection = new SqlConnection())
                    {
                        connection.Update(oldObject, newObject);
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    if (ioe.Message.Contains("both contain properties mapped to column"))
                    {
                        throw;
                    }
                }

                var scripts = logger.Scripts;
                Assert.AreEqual(1, scripts.Count);

                var script = scripts[0];
                var sql = script.Buffer.ToString();
                Assert.AreEqual(sql.IndexOf("Name"), sql.LastIndexOf("Name"), "Column appears more than once.");
            }
            finally
            {
                SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = true;
            }
        }
开发者ID:Paymentsense,项目名称:Dapper.SimpleSave,代码行数:34,代码来源:MultiplePropertiesSameColumnTests.cs

示例4: Update

 public bool Update(GroupSaleVehicle poco)
 {
     using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString))
     {
         return connection.Update(poco);
     }
 }
开发者ID:coderasm,项目名称:ABSBuybackMVCWebAPI,代码行数:7,代码来源:GSVRepository.cs

示例5: throws_on_update_with_duplicate_property_mappings_by_default

 public void throws_on_update_with_duplicate_property_mappings_by_default()
 {
     var oldObject = new TableB() { Name = "Captain Barbosa" };
     var newObject = new TableB() { Name = "Captain Jack Sparrow" };
     using (IDbConnection connection = new SqlConnection())
     {
         connection.Update(oldObject, newObject);
     }
 }
开发者ID:Paymentsense,项目名称:Dapper.SimpleSave,代码行数:9,代码来源:MultiplePropertiesSameColumnTests.cs

示例6: UpdateCustomer

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

示例7: UpdateCase

 public void UpdateCase(Case @case)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Update(CaseTableName,
                           new KeyValuePair<string, object>("编号", @case.编号),
                           ToKeyValuePairs(@case));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:10,代码来源:CaseInfoManager.cs

示例8: Main

        public static void Main()
        {
            using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
            {
                sqlConnection.Open();

                // using interface to track "Isdirty"
                var supplier = sqlConnection.Get<ISupplier>(9);
                //supplier.CompanyName = "Manning";

                // should return false, becasue there is no change.
                ObjectDumper.Write(string.Format("Is Update {0}", sqlConnection.Update(supplier)));

                supplier.CompanyName = "Manning";

                // should return true
                ObjectDumper.Write(string.Format("Is Update {0}", sqlConnection.Update(supplier)));

            }
        }
开发者ID:mehmetzantur,项目名称:dapper-net-sample,代码行数:20,代码来源:Contrib_Update_Entity_Using_Tracking.cs

示例9: 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 list = conn.Update(GetItem);
                }
            });
        }
开发者ID:sunkaixuan,项目名称:SqlSugar,代码行数:14,代码来源:UpdateItem.cs

示例10: Main

        public static void Main()
        {
            using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
            {
                sqlConnection.Open();

                var entity = sqlConnection.Get<Supplier>(9);
                entity.ContactName = "John Smith";

                sqlConnection.Update<Supplier>(entity);

                var result = sqlConnection.Get<Supplier>(9);

                ObjectDumper.Write(result.ContactName);
            }
        }
开发者ID:mehmetzantur,项目名称:dapper-net-sample,代码行数:16,代码来源:Contrib_Update_One_Entity.cs

示例11: Update

		public static void Update()
		{
			using (var cn = new SqlConnection(CONNECTION_STRING))
			{
				cn.Open();

				var c = cn.Get<Contact>(1);
				c.FirstName = "Jonathan";

				var updated = cn.Update(c);

				Console.WriteLine("Updated {0}", updated);
			}

			Console.ReadKey();
		}
开发者ID:jonathantower,项目名称:dapper,代码行数:16,代码来源:DapperExtension.cs

示例12: WarmUp

        public WarmUp()
        {
            Console.WriteLine("开启预热");
            //预热处理
            for (int i = 0; i < 2; i++)
            {
                using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
                {
                    var list = conn.QueryFirst<Test>("select top 1 * from Test");
                    conn.Update(new Test());
                }

                using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString))
                {
                    var list = conn.Queryable<Test>().Where(it => 1 == 2).ToList();
                    conn.Update(new Test());
                }
            }
            Console.WriteLine("预热完毕");
            Console.WriteLine("----------------比赛开始-------------------");
        }
开发者ID:sunkaixuan,项目名称:SqlSugar,代码行数:21,代码来源:WarmUp.cs

示例13: check_changes_only_appear_once

        private void check_changes_only_appear_once(DateTimePropertiesDto dto1, DateTimePropertiesDto dto2)
        {
            var logger = new MockSimpleSaveLogger();
            SimpleSaveExtensions.Logger = logger;
            SimpleSaveExtensions.DifferenceProcessed += SimpleSaveExtensions_DifferenceProcessed;

            try
            {
                using (IDbConnection connection = new SqlConnection())
                {
                    connection.Update(dto1, dto2);
                }
            }
            catch (InvalidOperationException)
            {
                //  Don't care
            }

            var scripts = logger.Scripts;
            Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts.");
            var sql = scripts[0].Buffer.ToString();
            Assert.AreEqual(sql.IndexOf("[DateTimeProperty]"), sql.LastIndexOf("[DateTimeProperty]"), "Should only be one occurence of [DateTimeProperty].");
            Assert.AreEqual(sql.IndexOf("[DateTimeOffsetProperty]"), sql.LastIndexOf("[DateTimeOffsetProperty]"), "Should only be one occurence of [DateTimeOffsetProperty].");
        }
开发者ID:Paymentsense,项目名称:Dapper.SimpleSave,代码行数:24,代码来源:DateTimePropertyTests.cs

示例14: SaveActivity

        public Activity SaveActivity(Activity activity)
        {
            var isInsert = activity.Id.Equals(0);

            using (var conn = new SqlConnection(ConnectionString))
            {
                if (isInsert)
                {
                    activity = conn.Insert(activity, "Id");
                }
                else
                {
                    conn.Update(activity, new Dictionary<string, object>() {{"Id", activity.Id}}, new[] {"Id"});
                }
            }

            return activity;
        }
开发者ID:grantcolley,项目名称:authorisationmanager,代码行数:18,代码来源:AuthorisationManagerData.cs

示例15: 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


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