18. juli 2008 - 17:56Der er
17 kommentarer og 1 løsning
loop i asp med data fra sql
Her er min kode:
<% Set Conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB; Data Source =WEBSERVER\SPC; Initial Catalog = STS_trm_1846091006; User Id = soeg; Password=soeg"
SQL = "SELECT * FROM Docs WHERE (DirName LIKE '%kvalitet%') AND (Extension = 'DOC' OR Extension = 'XLS' OR Extension = 'VSD' OR Extension = 'MHT') AND (LeafName LIKE '%projekt%')"
Set Rs = Conn.Execute(SQL)
If Rs.EOF Then Response.Write "<pre>Ingen dokumenter passer til søgningen</pre>" & vbcrlf Else
<% Set Conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB; Data Source =WEBSERVER\SPC; Initial Catalog = STS_trm_1846091006; User Id = soeg; Password=soeg" SQL = "SELECT * FROM Docs WHERE (DirName LIKE '%kvalitet%') AND (Extension = 'DOC' OR Extension = 'XLS' OR Extension = 'VSD' OR Extension = 'MHT') AND (LeafName LIKE '%projekt%')"
Set Rs = Conn.Execute(SQL) If Rs.EOF Then Response.Write "<pre>Ingen dokumenter passer til søgningen</pre>" & vbcrlf Else Do While Not rs.eof Response.Write "<table cellspacing='1' cellpadding='2' border='0' width='100%'>" & vbcrlf Response.Write " <tr>" & vbcrlf Response.Write " <td style='border-bottom: 1px solid #808080;'><font face='Verdana' size='1' color='#808080'>Dokumentnavn</font></td>" & vbcrlf Response.Write " </tr>" & vbcrlf Response.Write " <tr>" & vbcrlf Response.Write " <td><font face='Verdana' size='1' color='#000000'>" & Rs("Leafname") & "</font></td>" & vbcrlf Response.Write " </tr>" & vbcrlf Response.Write "</table>" & vbcrlf Rs.MoveNext Loop End If rs.close Set Rs = Nothing conn.close Set conn = nothing %>
Meget smartere med den korte udgave, nu mangler jeg kun én ting:
Outputtet nu ser således ud:
Dokumentnavn __________________________________ Projekt 1 Dokumentnavn __________________________________ Projekt 2 Dokumentnavn __________________________________ Projekt 3
Jeg kunne meget godt tænke mig outputtet således:
Dokumentnavn __________________________________ Projekt 1 Projekt 2 Projekt 3 Projekt 4
Dim color color = "#808080" Do While Not rs.eof If color = "#808080" Then color = "#000000" Else color = "#808080" End if Response.Write " <tr>" & vbcrlf Response.Write " <td style='border-bottom: 1px solid " & color & ";'><font face='Verdana' size='1' color='#000000'>" & Rs("Leafname") & "</font></td>" & vbcrlf Response.Write " </tr>" & vbcrlf Rs.MoveNext Loop Response.Write "</table>" & vbcrlf End If rs.close Set Rs = Nothing conn.close Set conn = nothing
Dim color color = " bgcolor='#C0C0C0'" Do While Not rs.eof If color = " bgcolor='#C0C0C0'" Then color = "" Else color = " bgcolor='#C0C0C0'" End if Response.Write " <tr>" & vbcrlf Response.Write " <td" & color & "><font face='Verdana' size='1' color='#000000'>" & Rs("Leafname") & "</font></td>" & vbcrlf Response.Write " </tr>" & vbcrlf Rs.MoveNext Loop Response.Write "</table>" & vbcrlf End If rs.close Set Rs = Nothing conn.close Set conn = nothing
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.