开发者

How to display data in table using asp.net

Could you help to give me the sample for display data in table using asp.net.

I using this SQL query:

SELECT 
    pvt.CityName, 
    pvt.[Deluxe Class], 
    pvt.[Superior Class], 
    pvt.[Standard Class] 
FROM 
    (SELECT 
         c.CityName, 
         h.Ho开发者_C百科telName, 
         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 

and using table:

   <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>

Sorry for something wrong because I am not good with SQL and asp.net program.

I am waiting for your help

many thanks Kosal


Don't loop like that. Keep code out of the markup. Look into using a GridView or ListView or one of the other DataBound controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜