Help needed converting classic ASP code to C#.NET

Last post 10-26-2009 4:26 PM by alex_brambila. 1 replies.

Sort Posts:

  • Help needed converting classic ASP code to C#.NET

    07-23-2009, 7:25 PM
    • Member
      point Member
    • sellestad
    • Member since 12-04-2007, 12:02 AM
    • Posts 4

    I'm trying to convert a site and this is giving me some trouble. I'm mainly confused by the nested query as I haven't seen this done in .NET, but I'm not expert either. Any ideas on converting this block would be appreciated.

    Thank You.

    <%
            Dim Conn,rs,rsBand,rsLOGO,sSQL,sALPHA,sComments
            
            If Request.Querystring("category_ID") > 0 Then Session("category_ID") = Request.Querystring("category_ID")
            
            '--Connect to Database
            Set Conn = Server.CreateObject("ADODB.Connection")
            Conn.Open "driver={SQL Server};server="
            
            '--Query to pull Alpha data from database
            sSQL = "SELECT alpha_letter, alpha_ID" _
                 & " FROM dbo.BABL_Alpha_Letter" _
                 & " WHERE category_ID = " & Session("category_ID")
            Set rs = Conn.Execute(sSQL)
            
            '--Loop through all of the Alpha Letters------------------
            Do Until rs.EOF
                sALPHA = rs("alpha_ID")
                Response.Write "<tr align='left'><td class='title'>&nbsp;&nbsp;&nbsp;&nbsp;<b>" & rs("alpha_letter") & "</b></td></tr>"
            
            '--Query to pull Band data from database
            sSQL = "SELECT *" _
                 & " FROM BABL_Band_Info" _
                 & " WHERE alpha_ID = " & sALPHA _
                 & " ORDER BY band_name"
            Set rsBAND = Conn.Execute(sSQL)
            
            Response.Write "<tr><td class='norm'>"
            
            '---Loop through each of the bands for that alpha letter
            Do Until rsBAND.EOF
                sComments = rsBAND("comments")
                Response.Write "<li><a href='" & rsBAND("band_url") & "' target='_blank'>" & rsBAND("band_name") & "</a>"
                            
                             If sComments <> "" Then
                                 Response.Write " - " & sComments
                             Else
                                 Response.Write ""
                             End If
            rsBAND.MoveNext
            Loop
            
            Response.Write "</td></tr>"
            
            rs.MoveNext
            Loop
            Conn.Close
            %>

  • Re: Help needed converting classic ASP code to C#.NET

    10-26-2009, 4:26 PM

    Change  conn to sqlclient.sqlconnection, rs to datatable, fill the datatable using an adapter, and iterate the rows using a For i = 0 to rs.rows.count, and it should all work just fine.

     

     

     

     

Page 1 of 1 (2 items)