本文整理汇总了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
}
}
}
示例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});
}
}
示例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();
}
示例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);
}
}
示例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");
}
示例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);
}
}
示例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");
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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});
}
}
示例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});
}
}
示例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);");
}
}
示例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();
}