如何使用C#中的数据集从数据库中获取最近注册的数据。
我想在两个给定日期之间获取最近注册的数据。 在开始月份之前,数据不得存在。
请帮助我,因为我被困在这里。
public DataSet getRecentRegistrations(DateTime startMonth, DateTime endMonth, long setaCode)
{
var query = (from _transaction in _entities.LevyTransactions
join _seta in _entities.Setas on _transaction.SetaCode equals _seta.SetaCode
join company_details in _entities.Organisations on _transaction.Refno equals company_details.Refno
where(_transaction.TransactionDate >= startMonth || startMonth == null) && (_transaction.TransactionDate <= endMonth || endMonth == null) && (_transaction.SetaCode == setaCode || setaCode < 0)
select new
{
SetaCode= _transaction.SetaCode,
RefNo = company_details.Refno,
TradingName = company_details.TradingName,
Seta=_transaction.SetaCode+" - "+_seta.Description,
SetaLevy = _transaction.SetaLevy,
SetaInterest = _transaction.SetaInterest,
SetaAdmin = _transaction.SetaAdmin,
SetaPenalty = _transaction.SetaPenalty,
TotalSetaCollected = _transaction.TotalSetaCollected
});
DataSet ds = new DataSet();
ds.Tables.Add(query.CopyToDataTable()); ds.Tables[0].TableName = "Table1";
ds.Tables.Add(headerTable("Transaction Month From : " + HelperService.formatDate("yyyy-MM-dd", startMonth) + " To : " + HelperService.formatDate("yyyy-MM-dd", endMonth), "Recently Registered Companies")); ds.Tables[1].TableName = "Table2";
var setaRows = (from DataRow dRow in ds.Tables[0].Rows
select new {
SetaCode = dRow["SetaCode"], Seta = dRow["Seta"]
}).Distinct();
ds.Tables.Add(setaRows.CopyToDataTable()); ds.Tables[2].TableName = "Table3";
return ds;
}