Web Hosting Offers
See the new scripts recently added to Dynamic Drive. Click here.
Original, practical CSS codes and examples such as CSS menus for your site.
    Search code samples  
 
  Keyword
 
 
 
   
 
 
  Code Samples
 
ASP
CSS
Dhtml
Html
Javascript
PHP
 
   
     LOGIN HERE  
 
Username
Password
Forgot Password
Verify Signup
 
 
 

ASP >> General

How can I find out if a record already exists in a database? If it doesn't, I want to add it.

Visitor Ratings (0) :

Description
You can do it by selecting the record, and then checking for EOF, like so:

<%
Dim strSQL
strSQL = "SELECT * FROM MyTable WHERE username = '" & _
Request.Form("username") & "'"
Set rs = db.Execute()

If rs.EOF Then
'Now do the insert
Else
Response.Write "Record exists"
End If
%>
For example You can check if the user exists and add him if he doesn't in ONE call!

First, we check if the record exists with the EXISTS keyword. EXISTS executes the query we tell it to (the SELECT) and returns a boolean value. If it finds the record, we return 'This record already exists!' to our recordset and do nothing else. If it doesn't exist, we execute our INSERT statement, and then return 'Record Added' to our recordset.You can either do this with a stored procedure or from ASP.
Code
Select All
 Rate this Resource