62,046
社区成员
发帖
与我相关
我的任务
分享
List<ResultType> lst = Search().ToList();
这样,就成为一个普通的强类型 List<>,可以用于绑定控件,也可以用于进行统计处理等等。
当然,凡是linq都要引用 System.Linq 命名空间。var num = Search().Count();
public class ResultType
{
public string ATM;
public DateTime dt;
public decimal money;
}
public IEnumerable<ResultType> Search()
{
using (var db = new SqlCeConnection(engine.LocalConnectionString))
{
db.Open();
var cmd = db.CreateCommand();
cmd.CommandText = "select * from yourTable order by ATM编号,插入时间";
var row = cmd.ExecuteReader();
var founds = new List<ResultType>();
while (row.Read())
{
var obj = new ResultType
{
ATM = (string)row["ATM编号"],
dt = (DateTime)row["插入时间"],
money = (decimal)row["金额"]
};
if (founds.Count > 0)
{
var last = founds.Last();
if (obj.ATM != last.ATM || obj.money != last.money) //如果当前行与上一行并不重复
founds.Clear();
}
founds.Add(obj);
if (founds.Count >= 3) //最近3条记录(或者更多条记录)的ATM编号和金额都是重复的
yield return obj;
};
}
}