0

这条简单的 sql 在 sql server 中完美运行...

Select it.Id as Id, it.Status as Status,
    (SELECT COUNT (*) FROM PickLocations as pl WHERE pl.PickBatchItemId = bi.Id) AS Counts
FROM PickBatches AS it
INNER JOIN PickBatchItems as bi ON it.Id = bi.PickBatchId

给我...

Id, Status, Counts
-------------------
1    1       2
2    1       0
3    2       2

但是在做出改变之后它不会抱怨......

Select it.Id as Id, it.Status as Status,
    (SELECT COUNT (pl.Id) FROM PickLocations AS pl WHERE bi.Id == pc.PickBatchItemId) AS Count
FROM PickBatches AS it
INNER JOIN PickBatchItems as bi ON it.Id == bi.PickBatchId

当我在 EntityDataSource CommandText 中使用它时,我得到...

Id, Status, Counts
-------------------
1    1       System.Collections.Generic.List`1[System.Data.Common.DbDataRecord]
2    1       System.Collections.Generic.List`1[System.Data.Common.DbDataRecord]
3    2       System.Collections.Generic.List`1[System.Data.Common.DbDataRecord]

显然缺少一些简单的东西......

更新

维克拉姆解决了问题。

使用选择count() 并使用Count[0]获取计数的索引

4

1 回答 1

1

VALUE添加到嵌套会SELECT返回一个 Int32 列表。

像这样绑定,返回值:

Count='<%# Eval("Count[0]") %>'
于 2012-03-09T11:39:52.740 回答