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


C# SqlQuery.Insert方法代码示例

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


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

示例1: Insert

 public void Insert(Doctor model)
 {
     using (var db = new DbManager())
     {
         var query = new SqlQuery<Doctor>();
         query.Insert(model);
     }
 }
开发者ID:frogconn,项目名称:Hospital,代码行数:8,代码来源:DoctorAccessor.cs

示例2: Insert

 public void Insert(Patient model)
 {
     using (var db = new DbManager())
     {
         var query = new SqlQuery<Patient>();
         query.Insert(model);
     }
 }
开发者ID:frogconn,项目名称:Hospital,代码行数:8,代码来源:PatientAccessor.cs

示例3: AddReduceItem

        public void AddReduceItem()
        {
            if (selectedReduce != null)
            {
                Journal newJournal = new Journal()
                {
                    Amount = 1,
                    Discount = 0,
                    ID_Partner = selectedReduce.ID_Partner,
                    Partner = selectedReduce,
                    User = User.CurrentUser,
                    ID_User = User.CurrentUser.ID_User,
                    Price = 0,
                    SaleDate = CurrentDate
                };

                JournalItemView view = new JournalItemView();
                view.DataContext = new JournalItemViewModel() { Item = newJournal };
                if (view.ShowDialog() == true)
                {
                    using (DbManager db = new DbManager())
                    {
                        db.BeginTransaction();
                        try
                        {
                            //inser new journal item
                            SqlQuery<Journal> query = new SqlQuery<Journal>(db);
                            query.Insert(newJournal);
                            db.CommitTransaction();
                        }
                        catch
                        {
                            db.RollbackTransaction();
                            throw;
                        }

                    }
                    PropertyChange("JournalList");
                    PropertyChange("DaySum");
                    PropertyChange("InKasaSum");

                }
            }
        }
开发者ID:vhytyk,项目名称:boginya-journal,代码行数:44,代码来源:JournalView.xaml.cs

示例4: AddJournalItem

        public void AddJournalItem()
        {
            if (!CanAddItem)
                return;
            FindWindow findWindow = new FindWindow();
            FindViewModel viewModel = new FindViewModel();
            //viewModel.SelectedTovar = viewModel.TovarList[0];
            findWindow.DataContext = viewModel;
            if (findWindow.ShowDialog() == true)
            {
                if (viewModel.SelectedTovar != null)
                {
                    Journal newJournal = new Journal()
                    {
                        Amount = 1,
                        Discount = 0,
                        ID_Tovar = viewModel.SelectedTovar.ID_Tovar,
                        Tovar = viewModel.SelectedTovar,
                        User = User.CurrentUser,
                        ID_User = User.CurrentUser.ID_User,
                        Price = viewModel.SelectedTovar.CinaProdazh,
                        SaleDate = CurrentDate
                    };
                    JournalItemView view = new JournalItemView();
                    view.DataContext = new JournalItemViewModel() { Item = newJournal };
                    if (view.ShowDialog() == true)
                    {
                        using (DbManager db = new DbManager())
                        {
                            db.BeginTransaction();
                            try
                            {
                                //inser new journal item
                                SqlQuery<Journal> query = new SqlQuery<Journal>(db);
                                query.Insert(newJournal);

                                if (!newJournal.IsRent) // if it's rent - reduce amount is not needed
                                {
                                    //reduce ostatok in tovar
                                    newJournal.Tovar.Ostatok -= (int) newJournal.Amount;
                                    SqlQuery<Tovar> query2 = new SqlQuery<Tovar>(db);
                                    query2.Update(newJournal.Tovar);
                                }
                                db.CommitTransaction();
                            }
                            catch {
                                db.RollbackTransaction();
                                throw;
                            }

                        }
                        PropertyChange("JournalList");
                        PropertyChange("DaySum");
                        PropertyChange("InKasaSum");

                    }
                }

            }
        }
开发者ID:vhytyk,项目名称:boginya-journal,代码行数:60,代码来源:JournalView.xaml.cs

示例5: restoreBackupTable

 void restoreBackupTable(BackupTable bkup, DataAccessObject dao, int totalCount, ref int currentCount)
 {
     SqlTable table = new SqlTable(bkup.TableName);
     int progressCount = 0;
     foreach (object[] row in bkup.Data) {
         currentCount++;
         progressCount++;
         if (progressCount > 17) {
             if (WFContext.BreakExecution) return;
             WFContext.Description = "Inserting record " + currentCount + " of " + totalCount + " to \"" + table.TableName + "\"...";
             WFContext.SetProgress(currentCount, totalCount);
             progressCount = 0;
         }
         SqlQuery q = new SqlQuery(dao);
         q.Insert(table);
         int f = -1;
         foreach (object value in row) {
             switch ((DataValueType)bkup.FieldTypes[++f]) {
                 case DataValueType.BooleanType: q.Values(new SqlFieldBoolean(bkup.FieldNames[f], table), (bool)value); break;
                 case DataValueType.DateTimeType: q.Values(new SqlFieldDateTime(bkup.FieldNames[f], table), (DateTime)value); break;
                 case DataValueType.FloatType: q.Values(new SqlFieldFloat(bkup.FieldNames[f], table), (double)value); break;
                 case DataValueType.IntegerType: q.Values(new SqlFieldInteger(bkup.FieldNames[f], table), (int)value); break;
                 case DataValueType.ShortStringType: q.Values(new SqlFieldShortString(bkup.FieldNames[f], table), (string)value); break;
                 case DataValueType.LongStringType: q.Values(new SqlFieldLongString(bkup.FieldNames[f], table), (string)value); break;
                 default: break;
             }
         }
         q.ExecuteNonQuery();
     }
 }
开发者ID:kyvkri,项目名称:mgone,代码行数:30,代码来源:MasterPage.master.cs

示例6: TestDataTypeTestInsert

		public void TestDataTypeTestInsert()
		{
			using (DbManager db = new DbManager())
			{
				var dt = new DataTypeTest2
				{
					Binary_ = new byte[2] { 1, 2 },
#if !ORACLE
					Boolean_ = true,
					Guid_ = Guid.Empty,
#endif
					Byte_ = 250,
					Bytes_ = new byte[] { 2, 1 },
					DateTime_ = DateTime.Now,
					Decimal_ = 9876543210.0m,
					Double_ = 12345.67890,
					Int16_ = 12345,
					Int32_ = 1234567890,
					Int64_ = 1234567890123456789,
					Money_ = 99876543210.0m,
					Single_ = 1234.0f,
					String_ = "Crazy Frog",

					Char_ = 'F',
					SByte_ = 123,
					//UInt16_   = 65432,
					//UInt32_   = 4000000000,
					//UInt64_   = 12345678901234567890,
#if !SQLCE
					Stream_ = new MemoryStream(5),
					Xml_ = new XmlTextReader(new StringReader("<xml/>")),
					XmlDoc_ = new XmlDocument()
#endif
				};

#if !SQLCE
				dt.XmlDoc_.LoadXml("<root><sql id=\"1\">Some Text</sql></root>");
#endif

				SqlQuery query = new SqlQuery(db);
				query.Insert(dt);
			}
		}
开发者ID:devmlog,项目名称:bltoolkit,代码行数:43,代码来源:DbManagerTest.cs

示例7: databaseWork

    void databaseWork()
    {
        int rows = 100;

        // create table
        string tableName = Guid.NewGuid().ToString().Replace("-", "");
        var fields = new DataValueType[] { DataValueType.IntegerType, DataValueType.DateTimeType, DataValueType.ShortStringType, DataValueType.LongStringType };
        var createActions = new List<DbAction>();
        createActions.Add(DbAction.EnsureTable(tableName, new string[] { "id" }, new DataValueType[] { DataValueType.IntegerType }));
        createActions.Add(DbAction.AddField(tableName, "f1", DataValueType.BooleanType, true, new BooleanDataValue(false)));
        createActions.Add(DbAction.AddField(tableName, "f2", DataValueType.DateTimeType, false, new DateTimeDataValue(DateTime.Now)));
        createActions.Add(DbAction.AddField(tableName, "f3", DataValueType.FloatType, false, new FloatDataValue(0)));
        createActions.Add(DbAction.AddField(tableName, "f4", DataValueType.ShortStringType, true, new ShortStringDataValue("test")));
        createActions.Add(DbAction.AddField(tableName, "f5", DataValueType.LongStringType, false, new LongStringDataValue("test")));
        WAFRuntime.Engine.Dao.DbProvider.UpdateDatabase(createActions);

        // inserting records
        var table = new SqlTable(tableName);
        var id = new SqlFieldInteger("id", table);
        var f1 = new SqlFieldBoolean("f1", table);
        var f2 = new SqlFieldDateTime("f2", table);
        var f3 = new SqlFieldFloat("f3", table);
        var f4 = new SqlFieldShortString("f4", table);
        var f5 = new SqlFieldLongString("f5", table);
        {
            for (int r = 0; r < rows; r++) {
                SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao);
                q.Insert(table);
                q.Values(id, r);
                q.Values(f1, false);
                q.Values(f2, DateTime.Now);
                q.Values(f3, (double)r);
                q.Values(f4, "My test string " + r);
                q.Values(f5, "My long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long test string " + r);
                q.ExecuteNonQuery();
            }
        }
        {
            // quering 10 records at the time
            for (int r = 0; r < rows; r++) {
                SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao);
                q.From(table);
                q.Select(f1);
                q.Select(f2);
                q.Select(f3);
                q.Select(f4);
                q.Where(id > r);
                using (var dr = q.ExecuteReader()) {
                    while (dr.Read()) { }
                }
            }
        }

        // deleting 1/10 of the records
        for (int r = 0; r < rows / 10; r++) {
            SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao);
            q.Delete(table);
            q.Where(id == r);
            q.ExecuteNonQuery();
        }

        // dropping table
        WAFRuntime.Engine.Dao.DbProvider.UpdateDatabase(new DbAction[] { DbAction.DeleteTable(tableName) }.ToList());
    }
开发者ID:kyvkri,项目名称:MG,代码行数:64,代码来源:Default.aspx.cs

示例8: NonUpdatableOnUpdate

		public void NonUpdatableOnUpdate()
		{
			using (var db = new DbManager())
			{
				db.BeginTransaction();

				var person = new Person1
				{
					FirstName  = "TestOnInsert",
					LastName   = "",
					MiddleName = "1",
					Gender     = 'M'
				};

				var sqlQuery = new SqlQuery<Person1>();

				sqlQuery.Insert(db, person);

				var p = db.GetTable<Person1>().Single(_ => _.FirstName == "TestOnInsert");

				Assert.AreEqual(person.MiddleName, p.MiddleName);

				person.PersonID   = p.PersonID;
				person.MiddleName = "should not be updated";

				sqlQuery.Update(db, person);

				p = db.GetTable<Person1>().Single(_ => _.FirstName == "TestOnInsert");

				Assert.AreNotEqual(person.MiddleName, p.MiddleName);
				
				db.RollbackTransaction();
			}
		}
开发者ID:pbludov,项目名称:bltoolkit,代码行数:34,代码来源:SqlTest.cs


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