Alterar e Excluir
Galera, estou começando com o ASP e estou com duvida de como se faz para ALTERAR e EXCLUIR informação de um banco de dados que no meu caso é o Acces.
Será que vcs poderiam me ajudar....
Meu problema é so pra alterar e excluir pois inserir eu já consegui fazer o mesmo:
Meu BD esta da Seguinte forma:
Tabela: Imoveis
Campos: descricao
Campos: edereco
Campos: corretor
Codigo de Inclusão (Formulario)
<form name="form1" action="upload_form2.asp" method="post" enctype="multipart/form-data"> <table width="597" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="597" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td> </td> <td><div align="right"><a href="javascript:history.go(-1)" class="texto8bold">« Voltar</a></div></td> </tr> </table> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="28%"><span class="legenda">Tipo de Imovel </span></td> <td width="72%"><% strQ = "SELECT * FROM tipo_imovel ORDER BY tp_imovel ASC"Set objRS = cn.Execute(strQ)Response.Write "<SELECT class='legenda' NAME='tp_imovel'>"Response.Write "<OPTION VALUE='' SELECTED></OPTION>" If Not objRS.EOF Then While Not objRS.EOF Response.Write "<OPTION class='legenda' VALUE='" & objRS("tp_imovel") & "'" If Request("id_tp_imovel") = objRS("tp_imovel") Then Response.Write " selected" Response.Write ">" & objRS("tp_imovel") & "</OPTION>" objRS.MoveNext WendEnd If Response.Write "</SELECT>" set objRS = Nothing%> <font class="legenda style1"> <a href="inserir_tp_imovel.asp" target="_blank" class="legenda style2" onClick="NewWindow(this.href,'name','450','500','yes');return false">Novo</a></font></td> </tr> </table> <br> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="50%"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="36%" class="texto8">Lançamento ? </td> <td width="64%"><font class="legenda style1"> <% lanc = "SELECT * FROM lancamento"Set RS_lanc = cn.Execute(lanc)Response.Write "<SELECT class='legenda' NAME='desc_lancamento'>"Response.Write "<OPTION VALUE='' SELECTED></OPTION>" If Not RS_lanc.EOF Then While Not RS_lanc.EOF Response.Write "<OPTION class='legenda' VALUE='" & RS_lanc("desc_lancamento") & "'" If Request("id_lancamento") = RS_lanc("desc_lancamento") Then Response.Write " selected" Response.Write ">" & RS_lanc("desc_lancamento") & "</OPTION>" RS_lanc.MoveNext WendEnd If Response.Write "</SELECT>" Set RS_lanc = Nothing%></font></td> </tr> </table></td> <td width="50%"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="33%"><span class="legenda">Aluguel / Venda </span></td> <td width="67%"><% alu_vend = "SELECT * FROM aluguel_venda ORDER BY desc_aluguel ASC"Set RS_alu_vend = cn.Execute(alu_vend)Response.Write "<SELECT class='legenda' NAME='desc_aluguel'>"Response.Write "<OPTION VALUE='' SELECTED></OPTION>" If Not RS_alu_vend.EOF Then While Not RS_alu_vend.EOF Response.Write "<OPTION class='legenda' VALUE='" & RS_alu_vend("desc_aluguel") & "'" If Request("id_aluguel") = RS_alu_vend("desc_aluguel") Then Response.Write " selected" Response.Write ">" & RS_alu_vend("desc_aluguel") & "</OPTION>" RS_alu_vend.MoveNext WendEnd If Response.Write "</SELECT>" set RS_alu_vend = Nothing%></td> </tr> </table></td> </tr> <tr> <td height="5" colspan="2"></td> </tr> <tr> <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="36%" class="texto8">Prioridade ? </td> <td width="64%"><font class="legenda style1"> <% priorid = "SELECT * FROM prioridade ORDER BY nivel_prioridade ASC"Set RS_priorid = cn.Execute(priorid)Response.Write "<SELECT class='legenda' NAME='nivel_prioridade'>"Response.Write "<OPTION VALUE='' SELECTED></OPTION>" If Not RS_priorid.EOF Then While Not RS_priorid.EOF Response.Write "<OPTION class='legenda' VALUE='" & RS_priorid("nivel_prioridade") & "'" If Request("id_prioridade") = RS_priorid("nivel_prioridade") Then Response.Write " selected" Response.Write ">" & RS_priorid("nivel_prioridade") & "</OPTION>" RS_priorid.MoveNext WendEnd If Response.Write "</SELECT>"Set RS_priorid = Nothing%> </font></td> </tr> </table></td> <td class="texto8"><label>Ativo? <select name="ativo" id="ativo"> <option value="1">Sim </option> <option value="0">Não</option> </select> </label></td> </tr> </table> <br> <tr> <td valign="top" height="185"><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td height="195"><table width="93%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><img src="../imagens/borda-esquerda_g.gif" width="30" height="195"></td> <td background="../imagens/fundo_g.gif"><table width="500" border="0" cellpadding="5" cellspacing="0" align="left"> <tr> <td width="33%"><div align="left"><span class="texto8">Foto do Imovel </span> <input type="file" name="imagem02" size="14" class="texto8"> <br> <br /> </div> <div align="center"></div></td> <td width="67%" class="texto8"><span class="legenda">Descrição Simples do Imovel </span><br /> <textarea name="desc_simples" class="texto8" cols="40" rows="4" wrap="virtual" id="desc_simples"></textarea> <br /> <span class="legenda">Valor <br /> <input name="valor" type="text" class="texto8boldred" id="valor" size="40" /> <br /> Referencia<br /> </span> <input name="referencia" type="text" class="texto8bold" id="referencia" size="40" /> <br /> <span class="legenda">Negrito Azul<br /> <input name="desc_negrito01" type="text" class="texto8bold" id="desc_negrito01" value="" size="40" /> </span> </td> </tr> </table></td> <td><img src="../imagens/borda-direita_g.gif" width="30" height="195"></td> </tr> </table></td> </tr> </table> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <tr> <td valign="top" height="100"><table width="91%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="5%"><img src="../imagens/borda-esquerda_gg.gif" width="30" height="313"></td> <td width="94%" background="../imagens/fundo_gg.gif"><table width="500" border="0" align="center" cellpadding="3" cellspacing="0" class="legenda"> <tr> <td width="95" class="legenda">Titulo Negrito </td> <td width="417"><input name="desc_negrito02" class="texto8bold" type="text" id="desc_negrito02" value="" size="50" /></td> </tr> <tr> <td colspan="2" class="legenda"><div align="center">Descrição do Imovel<br /> <textarea name="desc_imovel" class="texto8" cols="70" rows="10" wrap="virtual" id="desc_imovel"></textarea> </div></td> </tr> <tr> <td height="5" colspan="2" class="legenda"></td> </tr> <tr> <td class="legenda">Endereço</td> <td><input name="endereco" type="text" class="texto8" id="endereco" value="" size="60" /></td> </tr> <tr> <td class="legenda">Bairro </td> <td><input name="bairro" type="text" class="texto8" id="bairro" size="60" /></td> </tr> <tr> <td class="legenda">Corretor</td> <td><input name="corretor" type="text" class="texto8bold" id="corretor" size="60" /></td> </tr> <tr> <td colspan="2" class="legenda"><label> </label></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="submit" value="Enviar" /> <input name="Submit2" type="reset" class="mao" value="Limpar" style="CURSOR: hand" /> </div></td> </tr> </table></td> <td width="1%"><img src="../imagens/borda-direita_gg.gif" width="30" height="313"></td> </tr> </table> </table></form>
Codigo de postagem do Formulario
<%' Chamando Funções, que fazem o Upload funcionarbyteCount = Request.TotalBytesRequestBin = Request.BinaryRead(byteCount)Set UploadRequest = CreateObject("Scripting.Dictionary")BuildUploadRequest RequestBin' Recuperando os Dados Digitados ----------------------tp_imovel = UploadRequest.Item("tp_imovel").Item("Value")desc_lancamento = UploadRequest.Item("desc_lancamento").Item("Value")nivel_prioridade= UploadRequest.Item("nivel_prioridade").Item("Value")desc_aluguel = UploadRequest.Item("desc_aluguel").Item("Value")ativo = UploadRequest.Item("ativo").Item("Value")desc_simples = UploadRequest.Item("desc_simples").Item("Value")valor = UploadRequest.Item("valor").Item("Value")referencia = UploadRequest.Item("referencia").Item("Value")desc_negrito01 = UploadRequest.Item("desc_negrito01").Item("Value")desc_negrito02 = UploadRequest.Item("desc_negrito02").Item("Value")desc_imovel = UploadRequest.Item("desc_imovel").Item("Value")endereco = UploadRequest.Item("endereco").Item("Value")bairro = UploadRequest.Item("bairro").Item("Value")corretor = UploadRequest.Item("corretor").Item("Value")sData = Datehora = Time' Tipo de arquivo que esta sendo enviadotipo_imagem02 = UploadRequest.Item("imagem02").Item("ContentType")' Caminho completo dos arquivos enviadoscaminho_imagem02 = UploadRequest.Item("imagem02").Item("FileName")' Nome dos arquivos enviadosnome_imagem02 = Right(caminho_imagem02,Len(caminho_imagem02)-InstrRev(caminho_imagem02,"\"))' Conteudo binario dos arquivos enviadosimagem02 = UploadRequest.Item("imagem02").Item("Value")' pasta onde as fotos serao guardadaspasta = Server.MapPath("..\fotos\")nome_imagem02 = "\"&nome_imagem02' pasta + nome dos arquivoscimagem02 = "..\fotos" + nome_imagem02 ' Fazendo o Upload do arquivo selecionadoif cimagem02="..\fotos\" then cimagem02="..\fotos\sem-foto.jpg"end ifif imagem02 <> "" thenSet ScriptObject = Server.CreateObject("Scripting.FileSystemObject")Set MyFile = ScriptObject.CreateTextFile(pasta & nome_imagem02)For i = 1 to LenB(imagem02)MyFile.Write chr(AscB(MidB(imagem02,i,1)))NextMyFile.Closeend if' Conecta-se ao Banco de Dadosurl_conexao = Server.MapPath("..\bd\bd.mdb")set conexao = Server.CreateObject("ADODB.Connection")conexao.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&url_conexao %><% if ativo="Não" then ativo="0" end if if ativo="Sim" then ativo="1" end if%><%' cadastra os dados no banco de dadossql = "Insert into imovel(tp_imovel,desc_lancamento,desc_aluguel,nivel_prioridade,ativo,imagem02,desc_simples,valor,referencia,desc_negrito01,desc_negrito02,desc_imovel,endereco,bairro,corretor,data,hora) values('"&tp_imovel&"','"&desc_lancamento&"','"&desc_aluguel&"','"&nivel_prioridade&"','"&ativo&"','"&cimagem02&"','"&desc_simples&"','"&valor&"','"&referencia&"','"&desc_negrito01&"','"&desc_negrito02&"','"&desc_imovel&"','"&endereco&"','"&bairro&"','"&corretor&"','"&sData&"','"&hora&"')"Conexao.Execute(sql)%><style type="text/css"><!--.style1 { color: #FF0000; font-weight: bold;}.style2 {color: #FF0000}.texto8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: normal; color: #333333; text-decoration: none}--></style><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"><table width="774" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="../imagens/topo.gif" alt="z" width="774" height="150" border="0" usemap="#MapMap" /> <map name="MapMap" id="MapMap"> <area shape="rect" coords="530,111,624,131" href="seg_pag_asp/encomenda/index.html" target="2" /> <area shape="rect" coords="160,111,241,130" href="seg_pag_asp/home.html" target="2" /> <area shape="rect" coords="671,113,769,135" href="seg_pag_asp/mail/index.html" target="2" /> <area shape="rect" coords="407,110,482,130" href="seg_pag_asp/cadastro_imovel/index.html" target="2" /> <area shape="rect" coords="290,112,359,130" href="seg_pag_asp/empresa/index.html" target="2" /> </map> </td> </tr></table><table width="774" border="0" cellspacing="0" cellpadding="0"> <tr class="texto8"> <td> <script language="JavaScript" type="text/javascript" class="texto8"> hoje = new Date() dia = hoje.getDate() dias = hoje.getDay() mes = hoje.getMonth() ano = hoje.getYear() if (dia < 10) dia = "0" + dia if (ano < 2000) ano = "19" + ano function CriaArray (n) { this.length = n } NomeDia = new CriaArray(7) NomeDia[0] = "Domingo" NomeDia[1] = "Segunda" NomeDia[2] = "Terça" NomeDia[3] = "Quarta" NomeDia[4] = "Quinta" NomeDia[5] = "Sexta" NomeDia[6] = "Sábado" NomeMes = new CriaArray(12) NomeMes[0] = "Janeiro" NomeMes[1] = "Fevereiro" NomeMes[2] = "Março" NomeMes[3] = "Abril" NomeMes[4] = "Maio" NomeMes[5] = "Junho" NomeMes[6] = "Julho" NomeMes[7] = "Agosto" NomeMes[8] = "Setembro" NomeMes[9] = "Outubro" NomeMes[10] = "Novembro" NomeMes[11] = "Dezembro"function escreveData(){ if (ano == '19100') ano = '2000'; document.write (NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano)} </script> <script language="JavaScript" type="text/javascript">escreveData() </script> – Moradia Imobiliária – Tel.: (11) 6546.2299 – Fax: (11) 6943.2121 <hr size="1" /></td> </tr></table><table width="774" border="0" cellspacing="0" cellpadding="0" height="451"> <tr> <td width="177" valign="top" height="451"><img src="../imagens/menu(1).gif" alt="a" width="177" height="451" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="5,51,167,89" href="casas/index.asp" /> <area shape="rect" coords="7,92,170,131" href="sobrados/index.asp" /> <area shape="rect" coords="6,268,169,307" href="empresa/index.html" /> <area shape="rect" coords="6,226,170,263" href="aluguel/index.html" /> <area shape="rect" coords="7,179,170,219" href="terreno/index.asp" /> <area shape="rect" coords="5,312,169,350" href="cadastro_imovel/index.html" /> <area shape="rect" coords="5,7,173,44" href="lancamento/index.html" /> <area shape="rect" coords="8,135,168,178" href="apartamentos/index.asp" /> <area shape="rect" coords="4,356,171,400" href="encomenda/index.html" /> <area shape="rect" coords="5,402,171,440" href="mail/index.html" /> </map> </td> <td width="597" height="451" align="left" valign="top"><table width="597" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="597"> </td> </tr> <tr> <td valign="top" height="19"><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td> <%' Mostra Mensagem de Confirmação na TelaResponse.write "Dados Cadastrados com Sucesso!"' Redireciona após 5 segundosresponse.write "<br><br>você será redirecionado em 5 segundos..<br>"response.write "<meta http-equiv='refresh' content='5; url=inserir_imovel.asp'/>"%> </td> </tr> </table> <br /></td> </tr> <tr> <td valign="top" height="10"> </td> </tr> </table></td> </tr> </table><table width="774" border="0" cellspacing="0" cellpadding="0"> <tr class="texto8"> <td><hr size="1" /> </td> </tr> <tr class="texto8"> <td><div align="center">MORADIA IMOBILIÁRIA â€â€œ <a href="mailto:contato@moradia.imb.br" class="texto8">contato@moradia.imb.br</a> â€â€œ Tel.: (11) 6546.2299 – Fax: (11) 6943-2121</div></td> </tr></table></body>
Agora não tenho nem ideia como faço pra Alteração e Exclusão se Alguem puder me ajudar eu agradeço....
Como disse eu estou começando a mexer com ASP
Valew
Discussão (1)
Carregando comentários...