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


C# SqlConnection.Insert方法代码示例

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


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

示例1: Insert

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

示例2: AddCustomer

 public void AddCustomer(Customer customer)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(CustomerTableName, ToKeyValuePairs(customer));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:8,代码来源:ClientInfoManager.cs

示例3: AddCase

 public void AddCase(Case @case)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(CaseTableName, ToKeyValuePairs(@case));
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:8,代码来源:CaseInfoManager.cs

示例4: SetupDB

        private static void SetupDB()
        {
            var dbrecreated = false;
            using (var connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;Initial Catalog=Master;Integrated Security=True"))
            {
                connection.Open();
                try
                {
                    connection.Execute(@" DROP DATABASE SimplecrudDemoWebsite; ");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("database drop  failed - close and reopen VS and try again:" + ex.Message);
                }

                try
                {
                    connection.Execute(@" CREATE DATABASE SimplecrudDemoWebsite; ");
                    dbrecreated = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("database create failed - close and reopen VS and try again:" + ex.Message);
                }

            }
            if (!dbrecreated) return;
            using (var connection = Utilities.GetOpenConnection())
            {
                connection.Execute(@" create TABLE Car (Id int IDENTITY(1,1) not null  Primary Key, Make nvarchar(100) not null, ModelName nvarchar(100) not null) ");
                connection.Insert(new CarViewModel() { Make = "Honda", ModelName = "Civic" });
                connection.Execute(@" create TABLE Users (UserId int IDENTITY(1,1) not null Primary Key, FirstName nvarchar(100) not null, LastName nvarchar(100) not null, intAge int not null) ");
                connection.Insert(new UserViewModel() {Age = 42, FirstName = "Jim", LastName = "Smith"});
                connection.Execute(@" CREATE TABLE GUIDTest (guid uniqueidentifier NOT NULL,name varchar(50) NOT NULL, CONSTRAINT PK_GUIDTest PRIMARY KEY CLUSTERED (guid ASC))");
                connection.Insert<Guid>(new GUIDTestViewModel {name = "Example"});

                int x = 1;
                do
                {
                    connection.Insert(new User { FirstName = "Jim ", LastName = "Smith " + x, Age = x });
                    x++;
                } while (x < 101);

            }
        }
开发者ID:ChrisMalherbe,项目名称:Dapper.SimpleCRUD,代码行数:45,代码来源:Global.asax.cs

示例5: SaveRule

        public void SaveRule(Rule rule)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                connection.Insert(rule);

                connection.Close();
            }
        }
开发者ID:rioka,项目名称:30NuGetPackagesIn50Minutes,代码行数:11,代码来源:DapperDataAccess.cs

示例6: AddActivityToActivity

        public bool AddActivityToActivity(int parentActivityId, int activityId)
        {
            var activityActivity = new ActivityActivity() {ActivityId = activityId, ParentActivityId = parentActivityId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(activityActivity);
            }

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

示例7: AddActivityToRole

        public bool AddActivityToRole(int roleId, int activityId)
        {
            var roleActivity = new RoleActivity() {ActivityId = activityId, RoleId = roleId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(roleActivity);
            }

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

示例8: AddRoleToRole

        public bool AddRoleToRole(int parentRoleId, int roleId)
        {
            var roleRole = new RoleRole() {RoleId = roleId, ParentRoleId = parentRoleId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(roleRole);
            }

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

示例9: AddRoleToUser

        public bool AddRoleToUser(int userId, int roleId)
        {
            var userRole = new UserRole() {Id = userId, RoleId = roleId};

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Insert(userRole);
            }

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

示例10: LogError

		public void LogError(Error errorToLog)
		{
            Error result = null;

			//save info to DB
            using(SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CrestDB"].ConnectionString))
            {
               result = connection.Insert<Error>(errorToLog);
            }

            Clients.All.broadcastMessage(result);
		}
开发者ID:calvaryccm,项目名称:Crest,代码行数:12,代码来源:ErrorLogHub.cs

示例11: AddBookmarkRecord

 public void AddBookmarkRecord(string bookmarkName, object workflowInstanceId)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Insert(CaseWorkflowManager.BookmarkTableName,
                           new Dictionary<string, object>
                               {
                                   {CaseWorkflowManager.CaseIdColumnName, _caseId},
                                   {CaseWorkflowManager.WorkflowinstanceidColumnName, workflowInstanceId},
                                   {CaseWorkflowManager.BookmarkNameColumnName, bookmarkName}
                               });
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:14,代码来源:TaskActivityExtension.cs

示例12: AddMessage

 public void AddMessage(CaseMessage doc)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         var dictionary = new Dictionary<string, object>
                              {
                                  {"案件编号", doc.案件编号},
                                  {"Content", doc.Content},
                                  {"SenderName", doc.SenderUsername}
                              };
         connection.Insert(TableName, dictionary);
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:14,代码来源:CaseMessageManager.cs

示例13: 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.Insert(GetList);
                }
            });
        }
开发者ID:sunkaixuan,项目名称:SqlSugar,代码行数:14,代码来源:InsertList.cs

示例14: AddDoc

 public void AddDoc(CaseDoc doc)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         var dictionary = new Dictionary<string, object>
                              {
                                  {"文件名", doc.FileName},
                                  {"创建人", doc.UploadUserName},
                                  {"创建日期", doc.UploadDateTime},
                                  {"文件路径", doc.FilePath},
                                  {"案件编号", doc.案件编号}
                              };
         connection.Insert(CaseDocTableName, dictionary);
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:16,代码来源:CaseDocManager.cs

示例15: Insert

		public static void Insert()
		{
			var contact = new Contact
			{
				FirstName = "New",
				LastName = "Contact",
				Email = "[email protected]"
			};

			using (var cn = new SqlConnection(CONNECTION_STRING))
			{
				var id = cn.Insert(contact);
				Console.WriteLine("Inserted record ID: {0}", id);
			}

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


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