在可视C#中的datagridview中显示交叉表 [英] show a cross table in datagridview in visual c#

查看:295
本文介绍了在可视C#中的datagridview中显示交叉表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有3个表,它们是学生表,课程和结果.我想做的是我要在行中显示学生姓名和家庭,并在列标题中显示课程名称,并显示学生课程成绩,如何在DataGridView中做到这一点?

感谢您的帮助



I have 3 tables that they are student table, lesson and result. What that I want to do is that I want to show student name and family in row and show lesson name in columm header and show student lesson grade how can I do this in DataGridView?

Thanx for your help

推荐答案

是的,您可以这样做.您要查找的内容称为Join.这是非常简短的介绍 http://www.w3schools.com/sql/sql_join. asp [ ^ ]

该示例假定您的表看起来像什么.您需要对其进行调整以适合您的设计.
Yes you can do it. What you looking for is called Join Here is very brief intro http://www.w3schools.com/sql/sql_join.asp[^]

the example assumes what your tables may look like. You need to adjust it to fit your design.
SELECT first_name, family_name, lesson_name 
FROM students s
INNER JOIN lessons l
ON s.id = l.id


您可以使用Ysuf所说的联接查询(联接三个表)使用父子关系),并在联接查询的结果上使用数据透视查询.该结果可以绑定到gridview.

这是数据透视查询的示例.

http://www.mssqltips.com/tip.asp?tip=1019 [ ^ ]
You can use join query as Ysuf said (join the three tables using parent child relationship) and on the result of the join query use a pivoting query. That result can be bind to the gridview.

Here is an example of pivot query.

http://www.mssqltips.com/tip.asp?tip=1019[^]


您好,

看这篇文章:
C#数据透视表 [
Hi,

look at this Article:
C# Pivot Table[^]

Hope that helps.


这篇关于在可视C#中的datagridview中显示交叉表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆