如何将一些数据加载到GridView. [英] How can I load some data to GridView.

查看:58
本文介绍了如何将一些数据加载到GridView.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是东西.我创建了两个表,分别称为用户"和电话".在用户表中,有两列"id"和"name".因为一个用户拥有一个以上的电话号码如上所述创建了另一个称为电话"的表.因此电话表包含每个用户的所有电话号码.

用户表
id ------名称
100 ----- jack
200 ----- john


电话桌
id ------电话
100 ----- 12345
100 ----- 23456
200 ----- 34567
200 ----- 45678

所以现在我想将这两个表加载到单个网格视图中,如下所示(Visual Studio 2008,C#)

名称-----电话
插孔------- 12345,23456
约翰------- 34567,45678

我写了一个查询,

Here is the thing.I have created two tables called "User" and "Phone".In User table there are two columns "id" and "name".since one user has more than one phone number I''ve created another table called "Phone" as mentioned above. so phone table contains all the telephone numbers of each user.

User table
id-------name
100-----jack
200-----john


phone table
id-------phone
100-----12345
100-----23456
200-----34567
200-----45678

So now i want to load those two tables to a single grid view as below (Visual studio 2008,C#)

name-----phone
jack-------12345,23456
john-------34567,45678

I wrote a query as

SELECT U.name,P.phone
FROM tUser U,tPhone P 
WHERE U.id = P.id



但是我得到的输出如下

名称-----电话
插孔------- 12345
插孔------- 23456
约翰------- 34567
约翰------- 45678

我现在应该怎么办?这是不可能的,还是有其他方法来获得正确的输出?我正在等待一个肯定的答复.谢谢..



But I''m getting the output as below

name-----phone
jack-------12345
jack-------23456
john-------34567
john-------45678

What should I do now? Is it not possible or is there any other way to get the correct output? I''m Waiting for a possitive reply.thanks..

推荐答案

声明@phoneNumber varchar(1000)
选择@phoneNumber = COALESCE(@phoneNumber +'';'','''')+电话-列名
来自电话-表名

选择@phoneNumber
declare @phoneNumber varchar(1000)
select @phoneNumber = COALESCE(@phoneNumber + '';'','''') + phone --Column Name
from phone --Table Name

Select @phoneNumber


这篇关于如何将一些数据加载到GridView.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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