How do I get CF to reconize dupicate entries in my database?

fixx17 used Ask the Experts™
My next project is that I like to know how to get coldfusion to recongnize duplicate entries in my database.

Now I have a page that will query the database by entering in the Asset Tag Number and then it will <CFOUTPUT> the information.

And I have another page with a form that will insert information to the database.

What I want is when someone tries to add to the ASSETTAG Number to the database, it will catch a duplicate ASSETTAG Number and send the person off to another page not allowing them to enter this information and diplaying a message like " Asset Already entered."

Can any point me in the right direction?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

i know you're using Access so a simple thing to do is to go to the access db and make that column unique, i mean that no duplicate entries could be exist


Ok, I found it in Design View.  But what would happen now if I try to add an entry on the net and Access would not allow this.  Would I get an error thrown at me?

Of Course.  That is why you would usually have a <cftry>


<cfcatch type="database">
   There was an error.
   Message: #CFCATCH.message#
   Detail: #CFCATCH.detail#
   Exception Type: #CFCATCH.TYPE#

It will not work, but now you could explain in "english" why it failed.  Or not explain at all.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

dummy page

<script language="JavaScript">
   function fnRedirect(count){
      if ( count> 0 ){
           document.frmDummy.action = "error.cfm"
        document.frmDummy.action = "insert.cfm"
    document.frmDummy.method = "post"

<cfquery name="check2exit" datasource="dsn">
   select count(*) rec_count from table
   where Asset Tag Number = #form.assettagno#  

<cfset reccount = 0>  
<cfloop query="check2exit">
   <cfset reccount = rec_count>  

<body <cfoutput>onload="fnRedirect('#reccount#')</cfoutput>>
<form name="frmDummy">
  <input type="hidden" name="assettagno" value="#form.assettagno#">
  <!--- carry all the variable in the hidden variable as it need in insert page --->



show this tag name already exit.


do the needful to insert the data into databse with user input.


OK, trying to understand what is going on here.  Give me some time and I will get back to you.


Thanks, this did work, I just needed to change some parameters.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial