0

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

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

ok thank for your advise, if I want to add link to Gridview on hotelname how can I do.
use a Hyperlink field or a Template Column and add the Hyperlink yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.