using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhitePage.Data;
namespace TestDbfRecord
{
class Program
{
static void Main(string[] args)
{
//create table
List<DbFieldInfo> fields = new List<DbFieldInfo>();
DbFieldInfo field = new DbFieldInfo();
field.Name = "nickname";
field.Type = 'C';
field.Len = 100;
fields.Add(field);
field = new DbFieldInfo();
field.Name = "dt";
field.Type = 'D';
fields.Add(field);
string file = AppDomain.CurrentDomain.BaseDirectory +"\\demo.dbf";
using (DbfRecordset rs = DbfRecordset.Create(file, fields))
{
rs.CreateIndex("inick", "nickname", null);
rs.CreateIndex("idt", "dt", null);
Random ran = new Random(1000);
int recCount = 10;
for (int i = 1; i <= recCount; i++)
{
int days = ran.Next(0,1000);
string nick = "Jon:" + days.ToString();
System.Diagnostics.Debug.Print(nick);
rs.AddNew(); // append black
rs["nickname"] = nick;
rs["dt"] = DateTime.Now.AddDays(days);
rs.Update(); // commit changes
}
// aplay index tag inick - sorted by nickname
rs.Index = "inick";
System.Diagnostics.Debug.Print("--- sorted by nickname ----");
rs.MoveFirst();
while (!rs.Eof)
{
System.Diagnostics.Debug.Print(rs["nickname"].ToString());
rs.MoveNext();
}
rs.Index = "idt"; // aplay index tag idt
System.Diagnostics.Debug.Print("--- sorted by nickname ----");
rs.MoveFirst();
while (!rs.Eof)
{
System.Diagnostics.Debug.Print(rs["nickname"].ToString() + " " + rs["dt"].ToString());
rs.MoveNext();
}
rs.Close();
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhitePage.Data;
namespace TestDbfRecord
{
class Program
{
static void Main(string[] args)
{
//create table
List<DbFieldInfo> fields = new List<DbFieldInfo>();
DbFieldInfo field = new DbFieldInfo();
field.Name = "nickname";
field.Type = 'C';
field.Len = 100;
fields.Add(field);
field = new DbFieldInfo();
field.Name = "dt";
field.Type = 'D';
fields.Add(field);
string file = AppDomain.CurrentDomain.BaseDirectory +"\\demo.dbf";
using (DbfRecordset rs = DbfRecordset.Create(file, fields))
{
rs.CreateIndex("inick", "nickname", null);
rs.CreateIndex("idt", "dt", null);
Random ran = new Random(1000);
int recCount = 10;
for (int i = 1; i <= recCount; i++)
{
int days = ran.Next(0,1000);
string nick = "Jon:" + days.ToString();
System.Diagnostics.Debug.Print(nick);
rs.AddNew(); // append black
rs["nickname"] = nick;
rs["dt"] = DateTime.Now.AddDays(days);
rs.Update(); // commit changes
}
// aplay index tag inick - sorted by nickname
rs.Index = "inick";
System.Diagnostics.Debug.Print("--- sorted by nickname ----");
rs.MoveFirst();
while (!rs.Eof)
{
System.Diagnostics.Debug.Print(rs["nickname"].ToString());
rs.MoveNext();
}
rs.Index = "idt"; // aplay index tag idt
System.Diagnostics.Debug.Print("--- sorted by nickname ----");
rs.MoveFirst();
while (!rs.Eof)
{
System.Diagnostics.Debug.Print(rs["nickname"].ToString() + " " + rs["dt"].ToString());
rs.MoveNext();
}
rs.Close();
}
}
}
}
Комментариев нет:
Отправить комментарий