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