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

Deletando multiplos registro com checkbox


ursolouco

Pergunta

Deletando multiplos registro com checkbox (se possivel, edite seu relacionamento no banco de dados para realizar 'exclusão em cascata') usando consultas armazenadas:

index.asp

<!--#include file="adovbs.inc" -->
<%
        Session.LCID = 1046
	Response.Expires = 0
	cBanco = Server.MapPath("NWIND2000.mdb")
	strConn = "Provider=Microsoft.jet.oledb.4.0; Data Source=" & cBanco & ";"
	Set Conn = Server.CreateObject("adodb.connection")
	Conn.Open strConn

	Set objCmd = Server.CreateObject("adodb.command")

	With objCmd
  .ActiveConnection = Conn
  .CommandType = AdCmdStoredProc
  .CommandText = "cst_Lista"
	End With

	Set Rs = Server.CreateObject("adodb.recordset")
	Set Rs = objCmd.Execute
	Set objCmd = Nothing	

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Listando Produtos !</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="lista.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
	color: #990000;
	font-weight: bold;
}
.style2 {color: #990000}
-->
</style>
</head>

<body>
<form action="deletar.asp" method="post" name="Produtos" id="Produtos">
<table width="495" border="0" align="center" cellpadding="0" cellspacing="0" class="bordafina">
  <tr valign="middle">
    <td width="38" height="25" class="r1"><p align="center"><b>ID</b></p></td>
    <td width="327" height="25" class="r1"><p><b>&nbsp;Nome do Produto </b></p></td>
    <td width="100" height="25" class="r1"><p align="center"><b>Pre&ccedil;o</b></p></td>
    <td width="28" height="25" class="inf"><p align="center" class="style1">&nbsp;</p></td>
  </tr>
  <%
  	While Not Rs.Eof
  %>
  <tr>
    <td height="17" class="r1"><p align="center" class="style2">&nbsp;<% Response.Write(Rs(0))%></p></td>
    <td height="17" class="r1"><p>&nbsp;<% Response.Write(Rs(1))%></p></td>
    <td height="17" class="r1"><p align="center">&nbsp;<% Response.Write(FormatCurrency(Rs(2)))%></p></td>
    <td height="17" class="inf"><p align="center">
      <input name="idProduto" type="checkbox" id="idProduto" value="<% Response.Write(Rs(0))%>">
    </p></td>
  </tr>
  <%
  Rs.MoveNext
  Wend
  %>
  <tr>
    <td height="30" colspan="4"><p align="center">
      <input name="Submit" type="submit" class="botao" value="Excluir / Atualizar">
    </p></td>
  </tr>
</table>
</form>
</body>
</html>
<%
	Conn.Close
	Set Conn = Nothing
%>
cst_Lista:
 SELECT Products.ProductID, Products.ProductName, Products.UnitPrice FROM Products;
deletar.asp
<!--#include file="adovbs.inc" -->
<%

	id = Trim(Request.Form("idProduto")	)
	vId = Split(id, ",")

	If Not isNull(id) Then  	
  	cBanco = Server.MapPath("NWIND2000.mdb")
  	strConn = "Provider=Microsoft.jet.oledb.4.0; Data Source=" & cBanco & ";"
  	Set Conn = Server.CreateObject("adodb.connection")
  	Conn.Open strConn
  	
  	Set objCmd = Server.CreateObject("adodb.command")
  	
  	objCmd.CommandType = adcmdstoredProc
  	objCmd.ActiveConnection = Conn	
  	objCmd.CommandText = "cst_Deletar"  	
  	
  	For I = 0 to UBound(vId)
    objCmd.Parameters.Append objCmd.CreateParameter(":idDeletar", AdInteger, AdParamInput, 2, 1)
    objCmd(":idDeletar") = CInt(vId(i))
    objCmd.Execute
    objCmd.Parameters.Delete ":idDeletar"
  	Next
  	
  	Set objCmd = Nothing
  	Conn.Close
  	Set Conn = Nothing
  	Response.Redirect("index.asp")  	
	Else
  Response.Redirect("index.asp")
	End If

%>
cst_Deletar:
DELETE Products.ProductID, * FROM Products WHERE (((Products.ProductID)=[:idDeletar]));

Espero que seja util!!! cool.gif

Abraços!!!

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

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...