當前位置: 首頁>>代碼示例>>C#>>正文


C# Database.Execute方法代碼示例

本文整理匯總了C#中PetaPoco.Database.Execute方法的典型用法代碼示例。如果您正苦於以下問題:C# Database.Execute方法的具體用法?C# Database.Execute怎麽用?C# Database.Execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PetaPoco.Database的用法示例。


在下文中一共展示了Database.Execute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: btnReView_ItemClick

 void btnReView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     var et = gcloginfail.GetFocusedDataSource<t_loginfail>();
     if (null == et)
         return;
     if (MsgBox.ShowYesNoMessage(null,
         string.Format("確定要將 {0} MAC:{1} 審核通過嗎?", et.UserName, et.LoginMAC)) == System.Windows.Forms.DialogResult.No)
         return;
     var usr = GetCurUser<t_user>();
     using (var db = new Database()) {
         try {
             db.BeginTransaction();
             db.Delete("t_loginfail", "Id", et, et.Id);
             db.Execute(sql_addmac, et.LoginMAC, usr.UserName, usr.Guid);
             db.CompleteTransaction();
         } catch (Exception) {
             db.AbortTransaction();
     #if DEBUG
             throw;
     #endif
         }
     }
     using (var db = new Database()) {
         var etfail = db.Fetch<t_loginfail>("select * from t_loginfail");
         gcloginfail.DataSource = etfail;
         gcloginfail.RefreshDataSource();
         var etmac = db.Fetch<t_loginfail>("select * from t_mac");
         gcMac.DataSource = etmac;
         gcMac.RefreshDataSource();
     }
 }
開發者ID:MasterGao,項目名稱:DevWinFormFrame,代碼行數:31,代碼來源:MainView.cs

示例2: CreateTables

 public void CreateTables()
 {
     using (var db = new Database("DataSource=\"test.sdf\"; Password=\"chrissiespassword\"", "System.Data.SqlServerCe.4.0")) {
         db.Execute("CREATE TABLE Person (Id int IDENTITY(1,1) PRIMARY KEY, LastName nvarchar (40) NOT NULL, FirstName nvarchar (40), AddressId int NOT NULL);");
         db.Execute("CREATE TABLE Address (Id int IDENTITY(1,1) PRIMARY KEY, Street nvarchar (40) NOT NULL, HouseNumber nvarchar (10));");
     }
 }
開發者ID:tarwn,項目名稱:PetaPocoSample,代碼行數:7,代碼來源:TwoTableSample.cs

示例3: ResetDatabase

        protected override void ResetDatabase()
        {
            using (var database = new Database("SQLiteTest"))
            {
                database.BeginTransaction();

                database.Execute(new Sql("DELETE FROM Entity"));
                database.Execute(new Sql("DELETE FROM sqlite_sequence WHERE name = @0", "Entity"));

                database.CompleteTransaction();
            }
        }
開發者ID:TrevorPilley,項目名稱:MicroORM.Benchmark,代碼行數:12,代碼來源:PetaPocoBenchmark.cs

示例4: SetPoints

        public void SetPoints(int trackId, TrackPoint[] points)
        {
            var sb = new StringBuilder();
            for (int i = 0; i < points.Length; i++)
            {
                if (i % 1000 == 0)
                {
                    if(sb.Length>0) sb.Remove(sb.Length - 1, 1);
                    sb.AppendLine(";").AppendLine("insert into MR.tTrackPoint (TrackId, Idx, Lat, Lon, Elevation, PointTime) values ");
                }

                var p = points[i];
                sb.AppendLine().Append("(")
                    .Append(trackId).Append(",")
                    .Append(i).Append(",")
                    .Append(p.Lat.ToString(CultureInfo.InvariantCulture)).Append(",")
                    .Append(p.Lon.ToString(CultureInfo.InvariantCulture)).Append(",")
                    .Append(p.Elevation.ToString(CultureInfo.InvariantCulture)).Append(",")
                    .Append("'").Append(p.PointTime.ToString("o",CultureInfo.InvariantCulture)).Append("'")
                    .Append("),");

            }
            var sql = sb.ToString().TrimEnd(',');
            var db = new Database(_config.ConnectionString, "System.Data.SqlClient");

            try
            {
                db.Execute(sql);
            }
            catch (SqlException ex)
            {
                throw new Exception(sql, ex);
            }
        }
開發者ID:maxime-paquatte,項目名稱:MultiRando,代碼行數:34,代碼來源:TrackRepository.cs

示例5: deleteRoute

 public static void deleteRoute(int id)
 {
     using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
     {
         db.Execute("UPDATE route SET deleted = TRUE WHERE id = @0", id);
     }
 }
開發者ID:catflinger,項目名稱:bikes,代碼行數:7,代碼來源:route.cs

示例6: CreateDatabaseAndStuff

        public void CreateDatabaseAndStuff()
        {
            //creating the database
            _createDatabaseConn = new Database("create_db_conn");
            _createDatabaseConn.Execute("CREATE DATABASE TavernWenchTestDb");

            //creating test tables
            _testDatabaseConn = new Database("test_db_conn");
            _testDatabaseConn.Execute(@"CREATE TABLE Fruit (
                                              Name VARCHAR(60),
                                              Color VARCHAR(60)
                                        );");

            _testDatabaseConn.Execute(@"CREATE TABLE Actor (
                                              Id INT IDENTITY(1,1) NOT NULL,
                                              LastName VARCHAR(60)
                                        );");
        }
開發者ID:rzuquim,項目名稱:tavernwench,代碼行數:18,代碼來源:RememberGimmePersistence.cs

示例7: SaveOffice

        public static void SaveOffice(string catalog, string regionalDataFile, string officeCode, string officeName,
            string nickName,
            DateTime registrationDate, string currencyCode, string currencySymbol, string currencyName,
            string hundredthName, string fiscalYearCode,
            string fiscalYearName, DateTime startsFrom, DateTime endsOn,
            bool salesTaxIsVat, bool hasStateSalesTax, bool hasCountySalesTax,
            int quotationValidDays, decimal incomeTaxRate, int weekStartDay, DateTime transactionStartDate,
            bool isPerpetual, string valuationMethod, string logo,
            string adminName, string username, string password)
        {
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        string sql = File.ReadAllText(regionalDataFile, Encoding.UTF8);
                        db.Execute(sql);

                        sql =
                            "SELECT * FROM office.add_office(@0::varchar(12), @1::varchar(150), @2::varchar(50), @3::date, @4::varchar(12), @5::varchar(12), @6::varchar(48), @7::varchar(48), @8::varchar(12), @9::varchar(50), @10::date,@11::date, @12::boolean, @13::boolean, @14::boolean, @15::integer, @16::numeric, @17::integer, @18::date, @19::boolean, @20::character varying(5), @21::text, @22::varchar(100), @23::varchar(50), @24::varchar(48));";
                        db.Execute(sql, officeCode, officeName, nickName, registrationDate, currencyCode,
                            currencySymbol, currencyName, hundredthName, fiscalYearCode, fiscalYearName, startsFrom,
                            endsOn,
                            salesTaxIsVat, hasStateSalesTax, hasCountySalesTax, quotationValidDays,
                            incomeTaxRate, weekStartDay, transactionStartDate, isPerpetual, valuationMethod, logo,
                            adminName,
                            username, password);

                        transaction.Complete();
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                if (ex.Code.StartsWith("P"))
                {
                    string errorMessage = Factory.GetDBErrorResource(ex);
                    throw new MixERPException(errorMessage, ex);
                }

                throw;
            }
        }
開發者ID:njmube,項目名稱:mixerp,代碼行數:44,代碼來源:Offices.cs

示例8: CreateDB

		public void CreateDB()
		{
			db = new Database(_connectionStringName);
			db.Execute(@"

DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS authors;

CREATE TABLE posts (
	id				bigint AUTO_INCREMENT NOT NULL,
	title			varchar(127) NOT NULL,
	author			bigint NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE authors (
	id				bigint AUTO_INCREMENT NOT NULL,
	name			varchar(127) NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

			");


			var a1 = new author();
			a1.name = "Bill";
			db.Insert(a1);

			var a2 = new author();
			a2.name = "Ted";
			db.Insert(a2);

			var p = new post();
			p.title = "post1";
			p.author = a1.id;
			db.Insert(p);

			p = new post();
			p.title = "post2";
			p.author = a1.id;
			db.Insert(p);

			p = new post();
			p.title = "post3";
			p.author = a2.id;
			db.Insert(p);

		}
開發者ID:Evans-Zhang,項目名稱:PetaPoco,代碼行數:48,代碼來源:MultiPocoTests.cs

示例9: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e) {
            if (!dxValidationProvider1.Validate()) { return; }

            if (txtPassword.Text != txtComfirmPassword.Text) {
                MsgBox.ShowMessage("","兩次輸入的密碼不一致!");
                return;
            }

            try {
                using (var db = new Database()) {
                    db.Execute("update t_user set [email protected] where [email protected]", Ultra.Surface.Common.Util.EncryptPwd(txtPassword.Text), this.CurUser);
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            } catch (Exception ex) {          
                throw ex;
            }

        }
開發者ID:ZixiangBoy,項目名稱:Ultra.Base,代碼行數:19,代碼來源:EditPassWord.cs

示例10: SetApiKey

 public void SetApiKey(int userId, string apiKey)
 {
     var db = new Database(_config.ConnectionString, "System.Data.SqlClient");
     db.Execute("update MR.tUser set ApiKey = @1 where UserId = @0", userId, apiKey);
 }
開發者ID:maxime-paquatte,項目名稱:MultiRando,代碼行數:5,代碼來源:UserRepository.cs

示例11: processMDCInpsections

        private static void processMDCInpsections(Permit permit, Database db)
        {
            //Cleanup DB to bring new points for permit
            Console.WriteLine("Cleaning Data from DB for Permit: " + permit.PermitNum);
            db.Execute(String.Format("DELETE FROM Inspection WHERE PermitNum = '{0}'", permit.PermitNum));
            db.Execute(String.Format("DELETE FROM PermitStatus WHERE PermitNum = '{0}'", permit.PermitNum));
                    
            Console.WriteLine("Getting Inspections for Permit: " + permit.PermitNum);
            List<Inspection> inspections = getMDCInspections(permit.PermitNum);
            DateTime? lastApprovedInspectionDate = permit.StatusDate;
            if (permit.AppliedDate != null)
            {
                PermitStatus status = new PermitStatus();
                status.PermitNum = permit.PermitNum;
                status.StatusPrevious = "APPLIED";
                status.StatusPreviousMapped = "Application Accepted";
                status.StatusPreviousDate = permit.AppliedDate;

                db.Insert("PermitStatus", "id", true, status);

                permit.StatusCurrent = status.StatusPrevious;
                permit.StatusCurrentMapped = status.StatusPreviousMapped;
                permit.StatusDate = status.StatusPreviousDate;
            }

            if (permit.IssuedDate != null)
            {
                PermitStatus status = new PermitStatus();
                status.PermitNum = permit.PermitNum;
                status.StatusPrevious = "ISSUED";
                status.StatusPreviousMapped = "Permit Issued";
                status.StatusPreviousDate = permit.IssuedDate;

                db.Insert("PermitStatus", "id", true, status);

                permit.StatusCurrent = status.StatusPrevious;
                permit.StatusCurrentMapped = status.StatusPreviousMapped;
                permit.StatusDate = status.StatusPreviousDate;
            }

            if (isPermitClosed(inspections))
            {
                PermitStatus status = new PermitStatus();
                status.PermitNum = permit.PermitNum;
                status.StatusPrevious = "CLOSED";
                status.StatusPreviousMapped = "Permit Finaled";
                status.StatusPreviousDate = lastApprovedInspectionDate;

                db.Insert("PermitStatus", "id", true, status);

                permit.StatusCurrent = status.StatusPrevious;
                permit.StatusCurrentMapped = status.StatusPreviousMapped;
                permit.StatusDate = status.StatusPreviousDate;
                permit.CompletedDate = status.StatusPreviousDate;

            }

            foreach (Inspection inspection in inspections)
            {
                db.Insert("Inspection", "Id", true, inspection);
            }
        }
開發者ID:openpermit,項目名稱:OpenPermit.NET,代碼行數:62,代碼來源:Program.cs

示例12: SetPassword

 public void SetPassword(string email, string passwordHash)
 {
     var db = new Database(_config.ConnectionString, "System.Data.SqlClient");
     db.Execute("update MR.tUser set Passwd = @1 where Email = @0", email, passwordHash);
 }
開發者ID:maxime-paquatte,項目名稱:MultiRando,代碼行數:5,代碼來源:UserRepository.cs

示例13: btnOK_Click

        private void btnOK_Click(object sender, EventArgs e)
        {
            var items = gcItem.GetDataSource<t_instockitem>();
            if (items == null || items.Count < 1) {
                MsgBox.ShowMessage("", "沒有商品信息,不能保存!");
                return;
            }
            if (items.Any(K => string.IsNullOrEmpty(K.ItemNo))) {
                MsgBox.ShowMessage("", "商品信息不完整!");
                return;
            }

            if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
                using (var db = new Database()) {
                    try {
                        db.BeginTransaction();
                        db.Execute("delete t_instockitem where [email protected]", InStockNo);
                        InStock.Remark = txtRemark.Text;
                        InStock.Num = items.Sum(k => k.Num);
                        InStock.OuterNo = txtOuterNo.Text;
                        db.Save(InStock);
                        items.ForEach(k => { k.Id = 0; db.Save(k); });

                        db.CompleteTransaction();
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }
            } else {

                InStock = new t_instock();
                InStock.Remark = txtRemark.Text;
                InStock.Guid = GuidKey;
                InStock.InStockNo = InStockNo;
                InStock.OuterNo = txtOuterNo.Text;
                InStock.Creator = this.CurUser;
                InStock.AuditDate = InStock.CreateDate = TimeSync.Default.CurrentSyncTime;
                InStock.Num = items.Sum(k => k.Num);

                using (var db = new Database()) {
                    try {
                        db.BeginTransaction();
                        db.Save(InStock);
                        items.ForEach(k => db.Save(k));

                        db.CompleteTransaction();
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }

            }

            DialogResult = DialogResult.OK;
            Close();
        }
開發者ID:ZixiangBoy,項目名稱:YongERP,代碼行數:58,代碼來源:InStockEditView.cs

示例14: btnInvalid_ItemClick

 void btnInvalid_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     var trd = gcUnAudit.GetFocusedDataSource<t_rettrade>();
     if (trd == null)
         return;
     using (var db = new Database()) {
         db.Execute("update t_rettrade set isinvalid=1 where [email protected]", trd.Guid);
     }
     gcUnAudit.RemoveSelected();
 }
開發者ID:ZixiangBoy,項目名稱:YongERP,代碼行數:10,代碼來源:MainView.cs

示例15: btnReView_ItemClick

 void btnReView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     var trd = gcUnAudit.GetFocusedDataSource<t_rettrade>();
     if (trd == null)
         return;
     using (var db = new Database()) {
         try {
             db.BeginTransaction();
             //入庫更新庫存
             db.Execute("exec p_retgoodsupdateinvt @0", trd.Guid);
             db.Execute("update t_rettrade set isaudit=1 where [email protected]", trd.Guid);
             db.CompleteTransaction();
             gcUnAudit.RemoveSelected();
         } catch (Exception) {
             db.AbortTransaction();
             throw;
         }
     }
 }
開發者ID:ZixiangBoy,項目名稱:YongERP,代碼行數:19,代碼來源:MainView.cs


注:本文中的PetaPoco.Database.Execute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。