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


C# SqlQuery.Values方法代码示例

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


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

示例1: 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

示例2: 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


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