Foros del Web » Programando para Internet » ASP Clásico »

Registros existentes!

Estas en el tema de Registros existentes! en el foro de ASP Clásico en Foros del Web. Hey hey! me gustaria saber como hacer para reconocer si un registro ya existe en mi base de datos, es decir; por ejemplo en un ...
  #1 (permalink)  
Antiguo 29/12/2004, 15:42
Avatar de messer  
Fecha de Ingreso: julio-2004
Mensajes: 467
Antigüedad: 20 años, 9 meses
Puntos: 5
Registros existentes!

Hey hey!

me gustaria saber como hacer para reconocer si un registro ya existe en mi base de datos, es decir; por ejemplo en un registro de usuarios, si alguien se quiere registrar como pepito, de manera que si "pepito" ya existe en la bd, exponga un mensaje de que ya existe.

imagino que tendría que realizar una busqueda primero, o algo por el estilo...

Gracias!!
Bye
__________________
<script type="text/messerScript"><!--
window.onload=function(){ loadMesserRules(this.href) }
--></script>
  #2 (permalink)  
Antiguo 29/12/2004, 15:58
 
Fecha de Ingreso: diciembre-2004
Ubicación: Bs. As. - Argentina
Mensajes: 200
Antigüedad: 20 años, 5 meses
Puntos: 0
tenes que primero mirar si existe con la siguietne sentencia

cSQL = "SELECT * from tabla WHERE Nombre = '" & pepito & "'"
oRs.open cSQL, oCon (ocon es la conexion con la base)
if not ors.eof then
EXISTE
else
GRABAS
end if
ors.close
set ors = nothing
__________________
Javo.
www.thesitewatcher.com
Monitoreo y Auditoría de Sitios de Internet
  #3 (permalink)  
Antiguo 04/01/2005, 04:55
 
Fecha de Ingreso: diciembre-2004
Mensajes: 197
Antigüedad: 20 años, 4 meses
Puntos: 1
como haria teniendo en cuenta que yo tengo un ASP que quiere grabar en la base de datos de la siguiente manera:

<%@ Language=VBScript %>
<%

' el siguiente if es un request que saca los daos del formulario
if Request.ServerVariables("REQUEST_METHOD") = "POST" then

strEMPRESA = Request.Form("empresa")
strDIRELOCAL = Request.Form("direlocal")
strTELLOCAL = Request.Form("tellocal")
strNOMBRE = Request.Form("nombre")
strAPELLIDO = Request.Form("apellido")
strDNI = Request.Form("dni")
strDIRECCION = Request.Form("direccion")
strLOCALIDAD = Request.Form("localidad")
strPROVINCIA = Request.Form("provincia")
strTELEFONO = Request.Form("telefono")
strCELULAR = Request.Form("celular")
strEMAIL = Request.Form("email")
strCP = Request.Form("cp")
strUSUARIO = Request.Form("usuario")
strPASSWORD = Request.Form("password")


' el siguiente str saca la hora del sistema para grabarla en el logueo

strDate = Now()
blnValid = True
strValid = "<p><font face=Arial color=RED><b>" & _
"Invalid entry...!!!</b></font></p>" & vbCrLf & _
"<ul><font face=Arial size=2>" & vbCrLf

' de aca en adelante todos los if son los que verifican si han o no llenado las casillas del formualrio devolviendo un
' mensaje que dice que tal campo esta vacio

if strEMPRESA = "" then
blnValid = False
strValid = strValid & "<li><b><font color=""Blue"">Por favor, ingresar el campo EMPRESA</b></font><br>" & vbCrLf
end if


if strDIRELOCAL = "" then
blnValid = False
strValid = strValid & "<li><b><font color=""Blue"">Por favor, ingresar el campo DIRECCION DEL LOCAL</b></font><br>" & vbCrLf
end if

if strTELLOCAL = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo TELEFONO DEL LOCAL</b></font><br>" & vbCrLf

end if

if strNOMBRE = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo NOMBRE</b></font><br>" & vbCrLf

end if

if strAPELLIDO = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo APELLIDO</b></font><br>" & vbCrLf

end if

if strDNI = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo DNI</b></font><br>" & vbCrLf

end if

if strDIRECCION = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo DIRECCION</b></font><br>" & vbCrLf

end if

if strLOCALIDAD = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo LOCALIDAD</b></font><br>" & vbCrLf

end if

if strTELEFONO = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo TELEFONO</b></font><br>" & vbCrLf

end if

if strCELULAR = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo CELULAR</b></font><br>" & vbCrLf

end if

if strEMAIL = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo CORREO ELECTRONICO</b></font><br>" & vbCrLf

end if

if strCP = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo CODIGO POSTAL</b></font><br>" & vbCrLf

end if

if strPROVINCIA = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo PROVINCIA</b></font><br>" & vbCrLf

end if

if strUSUARIO = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo USUARIO</b></font><br>" & vbCrLf

end if

if strPASSWORD = "" then
blnValid = False
strValid = strValid & "<li><font color=""Blue""><b>Por favor, ingresar el campo PASSWORD</b></font><br>" & vbCrLf

end if



' desde aca empieza la conexion a la base de datos, los campos a llenar y los valores a esos datos


if blnValid = True then
' notar que los valores estan en el mismo orden que estan los nombres de los campos en la base de datos no cambiarlos
' porque de lo contrario se ingresaran mal en la base.
strDSNPath = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("database\dex.mdb")
strSQL_Insert = "INSERT INTO userREG ( empresa, direlocal, tellocal, nombre, apellido, dni, direccion, localidad, provincia, telefono, celular, email, cp, usuario, password, Entry_Date)" & _
" VALUES ('" & strEMPRESA & "','" & strDIRELOCAL & "', '" & strTELLOCAL & "', '" & strNOMBRE & "','" & strAPELLIDO & "', '" & strDNI & "','" & strDIRECCION & "', '" & strLOCALIDAD & "', '" & strPROVINCIA & "', '" & _
strTELEFONO & "', '" & strCELULAR & "','" & strEMAIL & "', '" & strCP & "','" & strUSUARIO & "', '" & strPASSWORD & "', '" & strDate & "');"

Set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open strDSNPath
On error resume next
Conn.Execute strSQL_Insert
Conn.Close
Set Conn = Nothing
' SE CIERRA LA CONEXION

' empieza el IF de los errorres

if err.number <> 0 then

strValid = "<p align=center><font face=Arial size=4 color=#8000FF><b>" & _
"There Was An Error In The DataBase!<br>" & _
"<U>Error Number</U>: " & err.number & "<BR>" & _
"<U>Error Description</U>: " & err.description & "<br>" & _
"</b></font></p>" & _
"<p align=center><font face=Arial color=#8000FF><b>" & _
"Please Contact Our <a href=mailto:[email protected]>E-mail!</a>" & _
"</b></font></p>" & _
"<p align=center><font face=Arial color=#8000FF><b>" & _
"</b></font></p>"
else

strValid = "<h2 align=center><i><u><font face=Arial color=Red><b>" & _
"Base de datos actualizada!! Nuevo Usuario!! <br>" & _
"Nombre: " & strNOMBRE & "<br> " & _
"Apellido: " & strAPELLIDO & "<br> " & _
"Documento: " & strDNI & "<br> " & _
"</b></font></u></i></h2><br>" & _
"<h3 align=center><font face=Arial color=Red><b>Your name and password was submited succesfully!</font></b></h3><br>" & _
"<h3 align=center><font face=Arial color=Red><b><u>You are our new member now.</font></u></b></h3><br>" & _
"<p align=center><font face=Arial color=Gold><b>" & _
"</b></font></p>"
end if

else
strValid = strValid & "<table align=""center""border=3>"&_
"<tr> <td><form action=""First_Time.asp"" method=""POST"" name=""form1""> "&_
"<tr><td align=""Left""><b><font color=""Blue"">Your Full Name:&nbsp;&nbsp;&nbsp;&nbsp;</font><input type=""text"" name=""txtFullName""></b></tr></tr></td><br><br>" & _
"<tr><td align=""Left""><b><font color=""Blue"">User Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input type=""text"" name=""txtName""></b></tr></tr></td><br><br>" & _
"<tr><td align=""Left""><b><font color=""Blue"">User Password:&nbsp;&nbsp;&nbsp;&nbsp;</font><input type=""password"" name=""txtPassword""maxlength=""10""></b></tr></td>" & _
"<tr><td><br><input type=""Submit"" value=""Re-Try""></tr></td> "&_
"</table><hr width=""400"">"
end if
else

Response.Redirect("login.html")

end if

%>
<HTML>
<HEAD>

<title>Successfully</title>
</HEAD>
<body background=glacier.gif>
<table WIDTH="600" ALIGN="center" BORDER="0" CELLSPACING="3" CELLPADDING="3">
<br>

<tr>
<td>
<%
Response.Write strValid
%>
</td>
</tr>
</table>
<p><b><a href="login.html"><U>Click here to go back!</U></a></b></p>
</BODY>
</HTML>




donde inserto los codigos para saber si hay o no registros en mi base de datos?????
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:37.