我正在制作一个带有aspx网页的报告工具,该网页从SQL表中读取数据并将该数据插入到标签文本中。到目前为止,这很简单。我的问题是,如何从表中读取多行数据到一个asp.Label
例如,
印象:第1行;第2行:第3行; 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();
我一直在寻找并且没有找到任何具体到我的问题,所以如果有人可以帮助或指出我正确的方向,我们非常感谢。
更新
Eli的回答指出我正确的方向为将来寻找答案的人提供了这个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#阅读器中阅读[“Impression”]
答案 0 :(得分:0)
使用FOR XML将所有数据行放入您显示的格式中。如果您要发布数据样本以及表结构的样子,我们将能够更快地帮助您
有关您的类似申请,请参阅此答案:Make a query that show result in another column