这是当前的查询:
SELECT DeletedClIEnts.Reason,COUNT(DeletedClIEnts.Reason) AS Number,CAST(CAST(COUNT(DeletedClIEnts.Reason) AS float) / CAST(t.Total AS float) * 100 AS numeric(4,1)) AS percentageFROM DeletedClIEnts CROSS JOIN (SELECT COUNT(*) AS Total FROM DeletedClIEnts AS DeletedClIEnts_1 WHERE (ClinicID = @ClinicID)) AS tWHERE (DeletedClIEnts.ClinicID = @ClinicID) AND (DeletedClIEnts.TotalsIDent = @IDent)GROUP BY DeletedClIEnts.Reason,t.TotalORDER BY Number DESC
我想做的是不将DeletedClIEnts写入服务器,因为它已作为Datatable存在于我的程序的内存中,它只会减慢报告速度并使用我们不需要保存的信息填充数据库.
我的主要问题是:要么:
如何查询数据表以创建一个新的内存数据表,其结果与我写出sql服务器并使用上面的查询读回来的结果相同?
要么
如何在Microsoft Reports中为Tablix中的项目执行group by子句= FIElds!Reason.Value = FIElds!Number.Value = FIElds!percentage.Value类似于上面查询的返回结果?
解决方法 您可以使用Datatable.Select查询Datatable.Datatable table = GetDatatableResults();Datatable results = table.Select("SomeIntColumn > 0").copyToDatatable();
或者对于更复杂的查询,您可以使用liNQ查询Datatable:
Datatable dt = GetDatatableResults();var results = from row in dt.AsEnumerable() group row by new { SomeIDColumn = row.FIEld<int>("SomeIDColumn") } into rowgroup select new { SomeID = rowgroup.Key.someIDColumn,Sometotal = rowgroup.Sum(r => r.FIEld<decimal>("SomeDecimalColumn")) }; Datatable queryResults = new Datatable();foreach (var result in query) queryResults.Rows.Add(new object[] { result.someID,result.sometotal });总结
以上是内存溢出为你收集整理的c# – 如何查询内存中的DataTable以填充另一个数据表全部内容,希望文章能够帮你解决c# – 如何查询内存中的DataTable以填充另一个数据表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)