Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

iniciante_ASP

a simplificar o código

Recommended Posts

Meus amigosQuero fazer um consulta aleatória em um banco que me distribua os valores encontrados em uma tabela de 03 colunas com 03 linhas cada. Usei o código abaixo mas sei que é meio "forcação de barra" e não deu certo. Por favor, me ajudem a simplificar. E vez ou outra acusa o erro e"rror '80020009' Ocorreu uma exceção. /webpub/includes/central.asp, line 273 ". Gostaria de saber pq? Por favor me ajudem, sou iniciante em ASP<table width="620" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse"> <tr> <td height="20" width="5"><img border="0" src="Imagens/Images/Lat_Dir_Central.jpg"></td> <td height="20" bgcolor=black width="610" align="center"><Font color="white" face="Arial" size="2" ><b>Destaques</b></font></td> <td height="20" width="5"><img border="0" src="Imagens/Images/Lat_Esq_Central.jpg"></td></tr> <tr><td height="5" width="620" colspan="3"></td></tr> <tr><td height="5" width="620" colspan="3"></td></tr></table><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="620" id="AutoNumber10"> <tr> <td width="205" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> <td width="3" align="center" valign="top"></td> <td width="204" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> <td width="3" align="center" valign="top"></td> <td width="205" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> </td> </tr></table><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="620" id="AutoNumber14" height="3"> <tr> <td width="100%" height="10"></td> </tr></table><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="620" id="AutoNumber10"> <tr> <td width="205" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> <td width="3" align="center" valign="top"></td> <td width="204" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> <td width="3" align="center" valign="top"></td> <td width="205" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> </td> </tr></table><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="620" id="AutoNumber14" height="3"> <tr> <td width="100%" height="10"></td> </tr></table><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="620" id="AutoNumber10"> <tr> <td width="205" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> <td width="3" align="center" valign="top"></td> <td width="204" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> <td width="3" align="center" valign="top"></td> <td width="205" align="center" valign="top"> <% strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\webpub\DataBase\DBautomovel.mdb;" Set Conexao = Server.CreateObject("ADODB.Connection") Conexao.Open strCon ComandoSQL = "SELECT COUNT(*) AS total_registro FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) total_registros = bd("total_registro") Set bd = Nothing randomize() registro_sorteado = Int(total_registros *Rnd) + 1 ComandoSQL = "SELECT * FROM expedientes" Set bd = Conexao.Execute(ComandoSQL) If registro_sorteado > 1 Then bd.Move registro_sorteado End If response.write "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='204' id='AutoNumber11'>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdir_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundo_central.gif' align='center'><b>" & bd("razaosocial") & "</b></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesq_central.gif'></td></tr>" response.write "<tr><td width='100%' colspan='3' height='4'></td></tr>" response.write "<tr><td width='3'><img border='0' src='Imagens/Images/Latdirgrd_central.gif'></td>" response.write "<td width='199' background='Imagens/Images/Fundogrd_central.gif'><p align='center'><a href='mais.asp?numero=" & ("id") & "'><img src='" & bd("foto") & "' width='180' height='54' border='1' align='center'></a></td>" response.write "<td width='3'><img border='0' src='Imagens/Images/Latesqgrd_central.gif'></td></tr></table>" Conexao.Close Set registro_sorteado = Nothing Set bd = Nothing Set Conexao = Nothing Set ComandoSQL = Nothing %> </td> </td> </tr></table>

Compartilhar este post


Link para o post
Compartilhar em outros sites

o que tem na linha do erro?e o que o seu codigo deveria fazer?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Fala, MarioEu tenho um banco de dados que gostaria de fazer consultas randômicas e não repetitivas. As informações deveriam me retornar em uma tabela 3 linhas em 03 colunas (como uma matriz 3x3)O erro não ocorre sempre. Ele é intermitente. Se você quiser posso te enviar o BD para você entender e simularValeu

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.