2017-05-25 85 views
1

我正在制作一个报表工具,它具有一个aspx网页,可以从SQL表中读取数据并将该数据插入到标签的文本中。到目前为止,这很容易。我的问题是,如何可以读取的数据的多行从表到单个asp.Label如何从一个表中读取多行数据到一个单一的asp.Label

例如,

印象:ROW1; Row2:Row3; ROW4; ROW5。

SQL查询

SELECT a.Value 
From ImpressionEcho a 
Inner join PatientData p on a.P_ID p.P_ID where p.P_ID = 1 

给出了这样的数据

Mildly dilated aortic root 
Moderately dilated aortic root 
Possible dissection 
Mild mitral regurgitation 
Reduced LV diastolic compliance 
No significant valvular abnormalities 

ASPX供读者

<Table> 
<tr> 
<td colspan="2"> 
    <asp:Label ID="Aorta" runat="server" Text="Impression:" ForeColor="Black" Font-Underline="true"></asp:Label> 
</td> 
<td> 
    <asp:Label ID="ImpressionReader" runat="server" Text="AortaReader" ForeColor="Black" ></asp:Label> 
</td> 
</tr> 
</Table>    

C#代码的代码来调用读者

ImpressionReader.Text = reader["Value"].ToString(); 

我一直在四处搜寻,还没有找到任何具体的问题,所以如果任何人都可以帮助或指出我在正确的方向,它是不胜感激。

UPDATE

礼的回答指出我对于那些在未来这个寻找答案,这个正确的方向是SQL查询中使用

SELECT DISTINCT 
    STUFF((SELECT '; ' + Value 
    FROM ImpressionEcho data1 
    FOR XML PATH('')), 1, 1, '') [Impression] 
    FROM ImpressionEcho data 

这给了我

Mildly dilated aortic root; Moderately dilated aortic root; Possible dissection; Mild mitral regurgitation; Reduced LV diastolic compliance; No significant valvular abnormalities 

然后我可以从我的C#阅读器读取[“印象”]

+0

你能告诉你的代码! –

+0

@ S.Akbari编辑 – NMatheny

回答

0

使用FOR XML将所有数据行放入所显示的格式中。如果你想发布的数据样本,你的表结构是什么样子,我们希望能够帮助您更快

看到这个答案了类似的应用到你:Make a query that show result in another column

+0

很棒的发现!我添加了该链接的查询语法,它做到了! – NMatheny

相关问题