2010-07-09 10 views
0

Pourriez-vous m'aider à me donner l'exemple de données d'affichage dans une table en utilisant asp.net.Comment afficher les données dans une table en utilisant asp.net

Je cette requête en utilisant 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 

et en utilisant le tableau:

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

Désolé pour quelque chose de mal parce que je ne suis pas bon avec SQL et programme asp.net.

Je suis en attente de votre aide

merci beaucoup Kosal

Répondre

1

Ne pas boucler comme ça. Gardez le code hors du balisage. Regardez dans l'utilisation d'un GridView ou ListView ou l'un des autres contrôles DataBound.

+0

ok merci pour vos conseils, si je veux ajouter un lien vers Gridview sur hotelname comment puis-je faire. – Kosaly

+0

utilisez un champ Lien hypertexte ou une colonne Modèle et ajoutez le lien hypertexte vous-même. –

+0

ok merci encore – Kosaly

Questions connexes