Desculpem a demora pra postar o código, mais é que não estava dando para entrar, então.. segue o código da pagina de inclusão. é código feito no dreamweaver, então é bem lixo, mais funciona =) tipo... como explicado, o sistema tem que barrar a inclusão de produtos com o mesmo código entenderam?? eu tenho o campo código no form que o usuário vai digitar o código do produto, e se esse produto já existir, ele proibe o cadastro. =) bom.. ta ai o código... se alguém puder me ajudar, ficaria muito agradeçido! <%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "inclusao") Then
MM_editConnection = MM_produtos_STRING
MM_editTable = "produtos"
MM_editRedirectUrl = "adm.asp"
MM_fieldsStr = "codigo|value|subcategoria|value|produto|value|fabricante|value|detalhe|value|preço|value|precovelho|value|parcela|value|jornal|value|destaque|value|img_g|value|imga|value|imgb|value|imgc|value|imgd|value|categoria|value"
MM_columnsStr = "codigo|',none,''|subcategoria|',none,''|nome|',none,''|fabricante|',none,''|detalhe|',none,''|preço|',none,''|precovelho|',none,''|parcela|none,none,NULL|jornal|',none,''|destaque|',none,''|img_g|',none,''|imga|',none,''|imgb|',none,''|imgc|',none,''|imgd|',none,''|categoria|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim categoria
Dim categoria_numRows
Set categoria = Server.CreateObject("ADODB.Recordset")
categoria.ActiveConnection = MM_produtos_STRING
categoria.Source = "SELECT * FROM categorias"
categoria.CursorType = 0
categoria.CursorLocation = 2
categoria.LockType = 1
categoria.Open()
categoria_numRows = 0
%>
<%
Dim subcategoria
Dim subcategoria_numRows
Set subcategoria = Server.CreateObject("ADODB.Recordset")
subcategoria.ActiveConnection = MM_produtos_STRING
subcategoria.Source = "SELECT * FROM subcategoria WHERE categoria = '" + Replace(subcategoria__MMColParam, "'", "''") + "' ORDER BY descricao ASC"
subcategoria.CursorType = 0
subcategoria.CursorLocation = 2
subcategoria.LockType = 1
subcategoria.Open()
subcategoria_numRows = 0
%>
<%
Dim incluir
Dim incluir_numRows
Set incluir = Server.CreateObject("ADODB.Recordset")
incluir.ActiveConnection = MM_produtos_STRING
incluir.Source = "SELECT * FROM produtos"
incluir.CursorType = 0
incluir.CursorLocation = 2
incluir.LockType = 1
incluir.Open()
incluir_numRows = 0
Set Conexao = Server.CreateObject("ADODB.Connection")
Conexao.Open "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Server.MapPath("mdb/produtos.mdb")
cat = "SELECT * FROM categorias ORDER BY categorias"
Set Rs = conexao.Execute ( cat )
%>
</p>
<%
if Request.QueryString("categoria") = "" then
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form name="form1" method="get" action="<%= strURL %>">
<div align="center">
<span class="style1">Categoria:</span>
<SELECT name="categoria" class="medium" style="border-style:solid; border-width:1; FONT-SIZE: 8pt; FONT-FAMILY: Verdana">
<%
While (NOT categoria.EOF)
%>
<option value="<%=(categoria.Fields.Item("categorias").Value)%>"><%=(categoria.Fields.Item("categorias").Value)%></option>
<%
categoria.MoveNext()
Wend
If (categoria.CursorType > 0) Then
categoria.MoveFirst
Else
categoria.Requery
End If
%>
</SELECT>
<label>
<input name="continuar" type="submit" class="small" id="continuar" value="continuar">
</label>
<input name="area" type="hidden" value="incluir">
</div>
</form>
</td>
</tr>
</table>
<% end if
if Request.QueryString("categoria") <> "" then %>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form ACTION="<%=MM_editAction%>" method="POST" name="inclusao" class="medium" id="inclusao">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<center>
<table width="44%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F5F5F5">
<tr>
<td bgcolor="#FFFFFF" > </td>
<td bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF" > </td>
<td bgcolor="#FFFFFF" > </td>
</tr>
<tr>
<td width="16%" bgcolor="#FFFFFF"><span class="style1">Código:</span></td>
<td width="84%" bgcolor="#FFFFFF"><span class="style1">
<label>
<input name="codigo" type="text" class="medium" id="codigo" size="10">
</label>
</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Subcategoria:</span></td>
<td bgcolor="#FFFFFF">
<select name="subcategoria" size=1 class="medium style1" style="border-style:solid; border-width:1; FONT-SIZE: 8pt; FONT-FAMILY: Verdana">
<%
While (NOT subcategoria.EOF)
%>
<option value="<%=(subcategoria.Fields.Item("subcategoria").Value)%>"><%=(subcategoria.Fields.Item("descricao").Value)%></option>
<%
subcategoria.MoveNext()
Wend
If (subcategoria.CursorType > 0) Then
subcategoria.MoveFirst
Else
subcategoria.Requery
End If
%>
</select>. </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Produto:</span></td>
<td bgcolor="#FFFFFF"><span class="style1">
<label>
<input name="produto" type="text" class="medium" id="produto" size="50">
</label>
</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Fabricante:</span></td>
<td bgcolor="#FFFFFF"><input name="fabricante" type="text" class="medium " id="fabricante" size="50"></td>
</tr>
<tr>
<td valign="top" bgcolor="#FFFFFF"><span class="style1">Detalhe:</span></td>
<td bgcolor="#FFFFFF"><span class="style1">
<label>
<textarea name="detalhe" cols="150" rows="10" class="medium" id="detalhe"></textarea>
</label>
</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Preço:</span></td>
<td bgcolor="#FFFFFF"><input name="preço" type="text" class="medium " id="preço" size="10"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Preço Velho: </span></td>
<td bgcolor="#FFFFFF"><p class="style1">
<input name="precovelho" type="text" class="medium" id="precovelho" size="10">
</p> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Parcela:</td>
<td bgcolor="#FFFFFF"><span class="style1">
<input name="parcela" type="text" class="medium" id="parcela" value="0" size="10">
</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Jornal:</td>
<td bgcolor="#FFFFFF"><input name="jornal" type="text" class="medium" id="jornal" value="não" size="50"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">Destaque:</td>
<td bgcolor="#FFFFFF"><input name="destaque" type="text" class="medium" id="destaque" value="não" size="50"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Img G: </span></td>
<td bgcolor="#FFFFFF"><span class="style1">
<label>
<input name="img_g" type="text" class="medium" id="img_g" size="50">
</label>
</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Imga:</span></td>
<td bgcolor="#FFFFFF"><input name="imga" type="text" class="medium " id="imga" size="50"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Imgb:</span></td>
<td bgcolor="#FFFFFF"><input name="imgb" type="text" class="medium " id="imgb" size="50"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Imgc:</span></td>
<td bgcolor="#FFFFFF"><input name="imgc" type="text" class="medium " id="imgc" size="50"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style1">Imgd:</span></td>
<td bgcolor="#FFFFFF"><input name="imgd" type="text" class="medium " id="imgd" size="50"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><div align="center">
<label>
<input name="enviar" type="submit" class="small" id="enviar" value="enviar">
</label>
</div></td>
</tr>
</table>
</center></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="inclusao">
<%if Request.QueryString("categoria") <> "" then%>
<input type="hidden" name="categoria" value="<%=Request.QueryString("categoria")%>">
<% end if%>
</form>
</td>
</tr>
</table>
<%
categoria.Close()
Set categoria = Nothing
%>
<%
subcategoria.Close()
Set subcategoria = Nothing
%>
<%
incluir.Close()
Set incluir = Nothing
%>