2017-05-25 33 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

相關問題