Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Dificuldades com acesso a dados


deathcon4

Pergunta

Bem, estou tentando pegar os dados de um banco access e não sei muito bem asp.net, diferente do asp antigo o qual eu conheço bem. A página para acionar está em javascript com o metodo post com um botão submit.

O problema está em colocar os dados dentro da tabela, é diferente o antigo asp. Podem ver, não há grid, repeater e outras coisas que ainda não entendi muito bem. Quero percorrer o banco e listar os registros. Depois eu quero saber como inserir, alterar e apagar. Não tenho Webmatrix e nem

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
&lt;script language="vb" runat="server">
Dim mes, registro
Sub Page_Load(sender as Object, e as EventArgs)
Dim conexão as String
conexão = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="c:\trabalho\correios\clientes_mala_direta.accdb";Persist Security Info="False"; Dim objConnection as OleDbConnection 'declara objecto para conexão
objConnection = New OleDbConnection(connString) 'cria conexão
objConnection.Open() 'abre a conexão

Dim consulta as string = "SELECT * FROM clientes_mala_direta " & _
 "WHERE mes = '" & mes & "' and ano = '" & ano & "' and nome = '" & nome & "' and fatura = '" & fatura & "' and registro = '" & registro & _ & "';"

Editado por deathcon4
Adicionar tag's (Jonathan)
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Estou colocando em pedaços, pois não está aceitando a postagem de uma só vez.

'Cria um objeto Command

Dim objCommand as OleDbCommand

objCommand = New OleDbCommand(consulta, objConnection)

Dim Dr As OleDbDataReader

Dr = Comando.ExecuteReader

if r1 = "I" then

while Dr.read

Response.write(Dr.Item("registro") & <br>)

end while

conexão.Close() 'Fecha a conexão

objConnection.Close() 'Fecha a conexão à base de dados

End Sub

Dim mes, ano, registro as string

</script>

<html>
<head>
<title>
</title>
</head>
<body>

<table border="0" cellspacing="0" width="760" cellpadding="0">
  <tr>
    <td bgcolor="#000080" width="427" height="5"> </td>
    <td bgcolor="#000080" width="89" height="5"><b><span style="letter-spacing: -1pt"><font
    face="Arial" size="2" color="#FFFFFF">Mês:   <%Response.Output.write("mes")%></font></span></b></td>
    <td bgcolor="#000080" width="95" height="5"><b><span style="letter-spacing: -1pt"><font
    face="Arial" size="2" color="#FFFFFF">Ano:   <%response.write("ano")%></font></span></b></td>
    <td bgcolor="#000080" width="138"></td>
  </tr>
</table>

<table border="0" cellspacing="1" width="762" cellspacing="1" cellpadding="0">
  <tr>
    <td width="95" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Registro</font></b></td>
    <td width="75" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Fatura</font></b></td>
    <td width="75" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Cliente</font></b></td>
    <td width="89" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Nome</font></b></td>
    <td width="70" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Quantidade</font></b></td>
    <td width="73" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Peso</font></b></td>
    <td width="99" bgcolor="#FFBD5B" align="center"><b><font face="Arial" size="2">Peso c*bico</font></b></td>
    <td width="58" bgcolor="#FFBD5B" align="center"><font face="Arial" size="2"><b>Cep</b></font></td>
    <td width="141" bgcolor="#FFBD5B" align="center"><font face="Arial" size="2"><b>Pais</b></font></td>
    <td width="141" bgcolor="#FFBD5B" align="center"><font face="Arial" size="2"><b>Valor</b></font></td>    
  </tr>
</table>
<table width="763" cellspacing="1" cellpadding="0">
  <tr>
    <td width="84" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%Response.Output.Write("registro")%></font></td>
    <td width="86" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="69" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="66" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="82" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="64" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="66" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="66" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%response.write()%></font></td>
    <td width="124" align="center" bgcolor="#FEE29A"><font face="Arial" size="2"><%%></font></td>
  </tr>

<p>  </p>

<p align="center"><font face="Arial" size="3" color="#000080"><b>A informação foi
inserida com sucesso!</b></font> </p>

<p align="center"><font face="arial" size="2" color="navy"><%response.write()%></font> <%else%> </p>

<table width="512" cellspacing="1" cellpadding="0" align="center">
  <tr>
    <td bgcolor="#000080" height="20" width="480" align="left"><p align="center"> </td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF" height="30"
    style="border-right-style: outset; border-right-width: 1px; border-bottom-style: outset; border-bottom-width: 1px"
    width="512" align="left"><p align="center"><font face="Arial" size="2" color="#ff0000"><strong>Estas
    informações já existem no Banco.</strong></font></td>
  </tr>
</table>
<%end if
end if%>
<%if r1 = "D" then
 executar = "SELECT * FROM CartuchoCarretelArmazenadosLidosGravados WHERE mes = '" & mes & "' and ano = '" & ano & "' and regional = '" & regional & "';" 
    Set verifica = DB.Execute(Executar)%>
<%if  verifica.EOF = true then%>
<div align="center">
<center>
<table border="1" width="517" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#000080" height="20" width="847" align="left"><p align="center"> </td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF" height="30"
    style="border-right-style: outset; border-right-width: 1px; border-bottom-style: outset; border-bottom-width: 1px"
    width="879" align="left"><p align="center"><font face="Arial" size="2" color="#ff0000"><strong>Estas
    informações não existem no Banco!</strong></font></td>
  </tr>
</table>
</center></div><%else
Executar = "Delete * FROM CartuchoCarretelArmazenadosLidosGravados " & _
"WHERE mes = '" & mes & "' and ano = '" & ano & "' and regional = '" & regional & "';" 
Set RecSet = DB.Execute(executar)
%>
<div align="center"><center>

<table border="1" width="517" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#000080" height="20" width="847" align="left"><p align="center"> </td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF" height="30"
    style="border-right-style: outset; border-right-width: 1px; border-bottom-style: outset; border-bottom-width: 1px"
    width="879" align="left"><p align="center"><font face="Arial" size="2" color="#ff0000"><strong>Registro
    deletado com sucesso!</strong></font></td>
  </tr>
</table>
</center></div><%end if
end if%>
<%if r1 = "A" then
    executar = "SELECT * FROM CartuchoCarretelArmazenadosLidosGravados WHERE mes = '" & mes & "' and ano = '" & ano & "' and regional = '" & regional & "';" 
    Set verifica = DB.Execute(Executar)%>
<%if  verifica.EOF = true then%>


<table width="512" cellspacing="1" cellpadding="0" align="center">
  <tr>
    <td bgcolor="#000080" height="20" width="480" align="left"><p align="center"> </td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF" height="30"
    style="border-right-style: outset; border-right-width: 1px; border-bottom-style: outset; border-bottom-width: 1px"
    width="512" align="left"><p align="center"><font face="Arial" size="2" color="#ff0000"><strong>Estas
    informações não existem no Banco.</strong></font></td>
  </tr>
</table>
<div align="center"><center>

<table border="1" width="516" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#000080" height="20" width="1213" align="left"> </td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF" height="30"
    style="border-right-style: outset; border-right-width: 1px; border-bottom-style: outset; border-bottom-width: 1px"
    width="1245" align="left"><p align="center"><font face="Arial" size="2" color="#ff0000"><strong>Registro
    alterado com sucesso!</strong></font></td>
  </tr>
</table>
</center></div><% end if
end if%>


<p><br>
<br>
<br>
</p>
<div align="center"><center>

<table border="0" cellpadding="0" cellspacing="0" width="98%" height="1">
  <tr>
    <td width="100%" height="4" colspan="3"><hr size="1" color="#000000">
    </td>
  </tr>
  <tr>
    <td width="57%" height="4"><p align="left"><font face="Arial" size="1" color="#000000"><strong>     </strong></font></td>
    <td width="23%" height="4"></td>
    <td width="20%" height="4" valign="middle"><p align="center"><a
    href="java script:history.back()"><img src="../imagens/retorno.gif"
    alt="Volta a página anterior" border="0" width="80" height="18"></a> </td>
  </tr>
</table>
</center></div>

</body>
</html>

Bem, coloquei, agora sim, todo o código. Obrigado pela atenção.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...