有 2 个对象之间存在关系。学生和班级。每个学生都有一个或多个班级。我想在网格控件(devexpress winform)中向学生展示,我不喜欢使用主细节。我想在单列中显示类,例如:A类-B类(在单行中)或像合并一样拆分行。
问问题
196 次
2 回答
0
可以创建一个未绑定的列以使用您的详细数据填充它。请参阅如何在 CustomUnboundColumnData 事件处理程序示例中访问详细视图的数据以了解如何执行此操作。
于 2018-11-20T06:51:27.290 回答
0
这些信息来自哪个数据库?
如果您正在使用Sql Server
,您可以像这样合并查询中的数据
declare @student table (studentid int, name varchar(20))
declare @class table (classid int, name varchar(20))
declare @studentclass table (studentid int, classid int)
insert into @student values (1, 'john'), (2, 'mary')
insert into @class values (1, 'english'), (2, 'mathematics')
insert into @studentclass values (1, 1), (1, 2), (2, 1)
select s.studentid,
s.name,
stuff(( replace (( select ' - ' + c.name
from @class c
inner join @studentclass sc on c.classid = sc.classid
where sc.studentid = s.studentid
order by c.name
For XML PATH ('')), '', '')
), 1, 3, '') as classes
from @student s
这将返回此结果:
studentid name classes
--------- ---- -------
1 john english - mathematics
2 mary english
其他数据库也可以这样做,语法会有所不同
于 2018-11-20T10:43:40.770 回答