0
您可以帮助给我使用asp.net在表格中显示数据的示例。如何使用asp.net在表格中显示数据
我使用这个SQL查询:
SELECT
pvt.CityName,
pvt.[Deluxe Class],
pvt.[Superior Class],
pvt.[Standard Class]
FROM
(SELECT
c.CityName,
h.HotelName,
tc.TourClass
FROM
tblCity2 c
LEFT JOIN
tblTourHotel2 th ON c.CityID = th.CityID
LEFT JOIN
tblHotel2 h ON th.HotelID = h.HotelID
LEFT JOIN
tblTourClass2 tc ON th.TourClassID = tc.TourClassID) t
PIVOT (
MAX(HotelName)
FOR TourClass IN ([Deluxe Class], [Superior Class], [Standard Class])
) AS pvt
,并使用表:
<table class="TableTour2" border="0" cellSpacing="0" cellPadding="0" width="500">
<tbody>
<tr>
<th scope=col>City</th>
<th scope=col>Deluxe Class</th>
<th scope=col>Superior Class</th>
<th scope=col>Standard Class</th>
</tr>
<%
Dim cnnPH As New System.Data.SqlClient.SqlConnection
Dim drPH As System.Data.SqlClient.SqlDataReader
Dim cmdPH As System.Data.SqlClient.SqlCommand
Try
cnnPH.ConnectionString = ConStr
cnnPH.Open()
cmdPH = New System.Data.SqlClient.SqlCommand("SELECT pvt.CityName, pvt.[Deluxe Class], pvt.[Superior Class], pvt.[Standard Class] " & _
" FROM ( SELECT " & _
" c.CityName, h.HotelName, tc.TourClass " & _
" FROM tblCity2 c " & _
" LEFT JOIN tblTourHotel2 th ON c.CityID = th.CityID " & _
" LEFT JOIN tblHotel2 h ON th.HotelID = h.HotelID " & _
" LEFT JOIN tblTourClass2 tc ON th.TourClassID = tc.TourClassID " & _
" WHERE th.TourID='1' " & _
") t " & _
" PIVOT (MAX(HotelName) FOR TourClass IN ([Deluxe Class], [Superior Class], [Standard Class]) " & _
") AS pvt", cnnPH)
drPH = cmdPH.ExecuteReader
While drPH.Read
%>
<tr>
<th class=sub><%Response.Write(drPH("CityName"))%> </th>
<td><% Response.Write(drPH("HotelName"))%></td>
<td><% Response.Write(drPH("HotelName"))%></td>
<td><% Response.Write(drPH("HotelName"))%></td>
</tr>
<%
End While
drPH = Nothing
cnnPH.Close() : cnnPH = Nothing
Catch ex As Exception
MsgBox(ex.Message)
drPH = Nothing
cnnPH.Close() : cnnPH = Nothing
End Try
%>
</tbody>
</table>
对不起,我有些不对劲,因为我不擅长与SQL和asp.net程序。
我等着你的帮助
千恩万谢 谷沙
好的感谢您的建议,如果我想添加链接到酒店名称的Gridview我该怎么办。 – Kosaly 2010-07-09 01:42:23
使用超链接字段或模板列并自己添加超链接。 – 2010-07-09 01:58:13
好的再次感谢你 – Kosaly 2010-07-09 02:29:52