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


C# SqlConnection.Execute方法代码示例

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


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

示例1: EditGradebook

        public void EditGradebook(GradeBookView.StudentGrade gbUpdate)
        {
            //this approach makes two calls to the database there is probably a way to do this all in one SQL Stored Procedure
               using (var cn = new SqlConnection(Config.GetConnectionString()))
               {
               var p = new DynamicParameters();
               p.Add("@RosterId", gbUpdate.RosterId);
               p.Add("@AssignmentId", gbUpdate.AssignmentId);
               p.Add("@Points",gbUpdate.Points);
               p.Add("@Score", gbUpdate.Score);

               if (//checks to see if grade exists
                   cn.Query<AssignmentGrade>("AssignmentGrade_GetByRosterIdAndAssignmentId", p,
                       commandType: CommandType.StoredProcedure)
                       .Any())
               {
                   cn.Execute("AssignmentGrade_UpdateScore", p, commandType: CommandType.StoredProcedure); //updates existing grade
               }
               else
               {
                   cn.Execute("AssignmentGrade_Insert", p, commandType: CommandType.StoredProcedure); //creates new grade
               }

               }
        }
开发者ID:naomish,项目名称:PracticeCsharp,代码行数:25,代码来源:GradeBookRepository.cs

示例2: Delete

 public void Delete(Guid orderId)
 {
     using (var connection = new SqlConnection(SqlConnectionLocator.LocalhostSqlExpress())) {
         connection.Execute(SqlQueries.DeleteOrderLineQuery, new {OrderId = orderId});
         connection.Execute(SqlQueries.DeleteOrderQuery, new {OrderId = orderId});
     }
 }
开发者ID:pierregillon,项目名称:DomainModelPersistencePatterns,代码行数:7,代码来源:DapperOrderRepository.cs

示例3: InitDataBase

 public void InitDataBase(string connectionString)
 {
     Dictionary<int, int> provinceDictionary = new Dictionary<int, int>();
     using (var connection = new SqlConnection(connectionString))
     {
         connection.Open();
         connection.Execute(Const.DBCreateScript);
         connection.Execute("insert into Province values(@Name, @Code);"
             , ProvinceData.GetProvinces());
         var provinces = connection.Query("select code, id from Province;");
         foreach (var province in provinces)
         {
             provinceDictionary.Add((int)province.code, (int)province.id);
         }
         connection.Close();
     }
     BulkUploadToSql bulk =
             BulkUploadToSql.Load(
                 HomeData.GetHomes()
                     .Select(
                         i =>
                             new Bulk.Home
                             {
                                 AddTime = DateTime.Now,
                                 BuildYear = i.BuildYear,
                                 City = i.City,
                                 Description = i.Description,
                                 Price = i.Price,
                                 Surface = i.Surface,
                                 ProvinceId = provinceDictionary[i.HomeProvince.Code]
                             }), "Home", 10000, connectionString);
     bulk.Flush();
 }
开发者ID:refrom,项目名称:ORMPerformanceTest,代码行数:33,代码来源:TestDapper.cs

示例4: EditUser

        public void EditUser(EditUserRequest editUser)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                var p = new DynamicParameters();
                p.Add("@UserId", editUser.LmsUser.UserId);
                p.Add("@IsStudent", editUser.IsStudent ? 1 : 0);
                p.Add("@IsParent", editUser.IsParent ? 1 : 0);
                p.Add("@IsTeacher", editUser.IsTeacher ? 1 : 0);
                p.Add("@IsAdmin", editUser.IsAdmin ? 1 : 0);

                cn.Execute("spUpdateUserRoles", p, commandType: CommandType.StoredProcedure);

                var p2 = new DynamicParameters();
                p2.Add("@UserId", editUser.LmsUser.UserId);
                p2.Add("@LastName", editUser.LmsUser.LastName);
                p2.Add("@FirstName", editUser.LmsUser.FirstName);
                p2.Add("@Email", editUser.LmsUser.Email);
                p2.Add("@SuggestedRole", editUser.LmsUser.SuggestedRole);
                p2.Add("@GradeLevelId", editUser.LmsUser.GradeLevelId);

                cn.Execute("spUpdateUserDetails", p2, commandType: CommandType.StoredProcedure);

            }
        }
开发者ID:jmullins1992,项目名称:Portfolio,代码行数:25,代码来源:SqlLmsUserRepository.cs

示例5: Initialize

        public void Initialize()
        {
            using (var connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True"))
            {
                connection.Open();
                try
                {
                    connection.Execute(@"ALTER DATABASE DapperSimpleCrudTestDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
                                                     DROP DATABASE DapperSimpleCrudTestDb ; ");
                }
                catch { }

                connection.Execute(@" CREATE DATABASE DapperSimpleCrudTestDb; ");
            }

            using (IDbConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=DapperSimpleCrudTestDb;Integrated Security=True"))
            {
                connection.Open();
                connection.Execute(@" create table Users (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, Age int not null, ScheduledDayOff int null) ");
                connection.Execute(@" create table Car (CarId int IDENTITY(1,1) not null, Make nvarchar(100) not null, Model nvarchar(100) not null) ");
                connection.Execute(@" create table City (Name nvarchar(100) not null, Population int not null, Version rowversion) ");
                connection.Execute(@" CREATE SCHEMA Log; ");
                connection.Execute(@" create table Log.CarLog (Id int IDENTITY(1,1) not null, LogNotes nvarchar(100) NOT NULL) ");

                connection.Execute("INSERT INTO USERS VALUES ('teste', 21, 1)");
            }
            Console.WriteLine("Created database");
        }
开发者ID:BrunoMVPCosta,项目名称:makeup.dapper,代码行数:28,代码来源:UnitTest1.cs

示例6: Add

 public void Add(Order order)
 {
     using (var connection = new SqlConnection(SqlConnectionLocator.LocalhostSqlExpress())) {
         connection.Execute(SqlQueries.InsertOrderQuery, order);
         connection.Execute(SqlQueries.InsertOrderLineQuery, order.Lines);
     }
 }
开发者ID:pierregillon,项目名称:DomainModelPersistencePatterns,代码行数:7,代码来源:DapperOrderRepository.cs

示例7: Setup

        private static void Setup()
        {
            using (var connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;Initial Catalog=Master;Integrated Security=True"))
            {
                connection.Open();
                try
                {
                    connection.Execute(@" DROP DATABASE DapperSimpleCrudTestDb; ");
                }
                catch (Exception)
                { }

                connection.Execute(@" CREATE DATABASE DapperSimpleCrudTestDb; ");
            }

            using (var connection = new SqlConnection(@"Data Source = (LocalDB)\v11.0;Initial Catalog=DapperSimpleCrudTestDb;Integrated Security=True"))
            {
                connection.Open();
                connection.Execute(@" create table Users (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, Age int not null, ScheduledDayOff int null, CreatedDate datetime DEFAULT(getdate())) ");
                connection.Execute(@" create table Car (CarId int IDENTITY(1,1) not null, Id int null, Make nvarchar(100) not null, Color nvarchar(100) not null, AgeInYears int not null, Model nvarchar(100) not null) ");
                connection.Execute(@" create table BigCar (CarId bigint IDENTITY(2147483650,1) not null, Make nvarchar(100) not null, Model nvarchar(100) not null) ");
                connection.Execute(@" create table City (Name nvarchar(100) not null, Population int not null) ");
                connection.Execute(@" CREATE SCHEMA Log; ");
                connection.Execute(@" create table Log.CarLog (Id int IDENTITY(1,1) not null, LogNotes nvarchar(100) NOT NULL) ");
                connection.Execute(@" CREATE TABLE [dbo].[GUIDTest]([Id] [uniqueidentifier] NOT NULL,[name] [varchar](50) NOT NULL, CONSTRAINT [PK_GUIDTest] PRIMARY KEY CLUSTERED ([Id] ASC))");
                connection.Execute(@" create table StrangeColumnNames (ItemId int IDENTITY(1,1) not null Primary Key, word nvarchar(100) not null, colstringstrangeword nvarchar(100) not null) ");
                connection.Execute(@" create table UserWithoutAutoIdentity (Id int not null Primary Key, Name nvarchar(100) not null, Age int not null) ");

            }
            Console.WriteLine("Created database");
        }
开发者ID:JotaAlava,项目名称:Dapper.SimpleCRUD,代码行数:31,代码来源:Program.cs

示例8: Add

 public void Add(Order order)
 {
     var persistentModel = _orderMapper.ToPersistentModel(order);
     using (var connection = new SqlConnection(SqlConnectionLocator.LocalhostSqlExpress())) {
         connection.Execute(SqlQueries.InsertOrderQuery, persistentModel);
         connection.Execute(SqlQueries.InsertOrderLineQuery, persistentModel.Lines);
     }
 }
开发者ID:pierregillon,项目名称:DomainModelPersistencePatterns,代码行数:8,代码来源:DapperOrderRepository.cs

示例9: Add

 public void Add(Order order)
 {
     var orderState = new Order.ToState().Build(order);
     using (var connection = new SqlConnection(SqlConnectionLocator.LocalhostSqlExpress())) {
         connection.Execute(SqlQueries.InsertOrderQuery, orderState);
         connection.Execute(SqlQueries.InsertOrderLineQuery, orderState.Lines);
     }
 }
开发者ID:pierregillon,项目名称:DomainModelPersistencePatterns,代码行数:8,代码来源:DapperOrderRepository.cs

示例10: Update

 public void Update(Order order)
 {
     using (var connection = new SqlConnection(SqlConnectionLocator.LocalhostSqlExpress())) {
         connection.Execute(SqlQueries.UpdateOrderQuery, order);
         connection.Execute(SqlQueries.DeleteOrderLineQuery, new {OrderId = order.Id});
         connection.Execute(SqlQueries.InsertOrderLineQuery, order.Lines);
     }
 }
开发者ID:pierregillon,项目名称:DomainModelPersistencePatterns,代码行数:8,代码来源:DapperOrderRepository.cs

示例11: ReCommit

        private static void ReCommit(SqlConnection db, SqlTransaction transaction, List<MovementRegisterItem> docs)
        {
            foreach (var item in docs.Reverse<MovementRegisterItem>())
                db.Execute(item.RollbackCommand, new { item.DocId }, transaction: transaction);

            foreach (var item in docs)
                db.Execute(item.CommitCommand, new { item.DocId }, transaction: transaction);
        }
开发者ID:Tupbich,项目名称:POS,代码行数:8,代码来源:MovementRegister.cs

示例12: WriteDeal

 public override void WriteDeal(string path, string serializedDeal)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Execute(@"delete from Deals where Id = @Id", new { Id = path });
         connection.Execute(@"insert Deals(Id, Value) values (@Id, @Value)",
             new {Id = path, Value = serializedDeal});
     }
 }
开发者ID:evilz,项目名称:solid-sample,代码行数:10,代码来源:SQLDealStorage.cs

示例13: Save

 public void Save(string id, string serializedDeal)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Execute(@"delete from Deals where Id = @Id", new { Id = id });
         connection.Execute(@"insert Deals(Id, Value) values (@Id, @Value)",
             new {Id = id, Value = serializedDeal});
     }
 }
开发者ID:evilz,项目名称:solid-sample,代码行数:10,代码来源:SQLDealStorage.cs

示例14: SqlServerTestSuite

 static SqlServerTestSuite()
 {
     using (var connection = new SqlConnection(ConnectionString))
     {
         // ReSharper disable once AccessToDisposedClosure
         Action<string> dropTable = name => connection.Execute([email protected]"IF OBJECT_ID('{name}', 'U') IS NOT NULL DROP TABLE [{name}]; ");
         connection.Open();
         dropTable("Stuff");
         connection.Execute(@"CREATE TABLE Stuff (TheId int IDENTITY(1,1) not null, Name nvarchar(100) not null, Created DateTime null);");
         dropTable("People");
         connection.Execute(@"CREATE TABLE People (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null);");
         dropTable("Users");
         connection.Execute(@"CREATE TABLE Users (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, Age int not null);");
         dropTable("Automobiles");
         connection.Execute(@"CREATE TABLE Automobiles (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null);");
         dropTable("Results");
         connection.Execute(@"CREATE TABLE Results (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, [Order] int not null);");
         dropTable("ObjectX");
         connection.Execute(@"CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);");
         dropTable("ObjectY");
         connection.Execute(@"CREATE TABLE ObjectY (ObjectYId int not null, Name nvarchar(100) not null);");
         dropTable("ObjectZ");
         connection.Execute(@"CREATE TABLE ObjectZ (Id int not null, Name nvarchar(100) not null);");
     }
 }
开发者ID:CarlSosaDev,项目名称:dapper-dot-net,代码行数:25,代码来源:TestSuites.cs

示例15: Execute

 public ActionResponse Execute() {
     using (var cn = new SqlConnection(_output.Connection.GetConnectionString())) {
         cn.Open();
         try {
             cn.Execute(_output.SqlDropStarView());
         } catch (SqlException) {
         }
         cn.Execute(_output.SqlCreateStarView());
     }
     return new ActionResponse();
 }
开发者ID:mindis,项目名称:Pipeline.Net,代码行数:11,代码来源:SqlStarViewCreator.cs


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