Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
Anderson Buzzi

Table com dados de SQL

Question

Sugestões que possam melhorar e aperfeiçoar o script são bem vindas!

Senti a necessidade de criar uma maneira mais genérica de mostrar os dados de um determinado SQL.

Desenvolvi esta função simples que recebe como parâmetro um comando.

Ela executará o SQL e irá gerar uma table com os registros.

Obs: não me preocupei com o visual, apenas com o resultado esperado.

index.asp

<html>
<!--#include file="funcoes.asp" -->
<body>
<%
call grid("SELECT * FROM USUARIOS")
Response.Write "<br>"
call grid("SELECT LOGIN as Login, SENHA as Senha FROM USUARIOS")
%>
</body>
</html>
funcoes.asp
<script LANGUAGE="vbscript" RUNAT="Server">
    sub grid(sql)
        Dim conObj
        Set conObj = Server.CreateObject("ADODB.Connection")
        conObj.Open "STRING DE CONEXÃO COM O BANCO DE DADOS"
        Dim rs
        Set rs = conObj.Execute(sql)
        
        Response.Write "<table border='0' width='100%'>"
        Response.Write "<tr>"
        'imprime as colunas
        i = 0
        do while i <= rs.Fields.Count-1
            Response.Write "<td><b>" & rs.fields(i).name & "</b></td>"
            i = i+1
        loop
        Response.Write "</tr>"
        'imprime os registros
        do while not rs.eof
            i = 0
            Response.Write "<tr>"
            do while i <= rs.Fields.Count-1
                Response.Write "<td>"&rs(i) & "</td>"
                i = i+1
            loop
            Response.Write "</tr>"
            rs.movenext
        loop
        
        Response.Write "</table>"
        
        Response.Write "<br>"
        
        rs.close
        conObj.close
        set rs = nothing
        set conObj = nothing
    end sub

</SCRIPT>

Edited by Anderson Buzzi

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

Cloud Computing


  • Forum Statistics

    • Total Topics
      148575
    • Total Posts
      644272
×
×
  • Create New...