Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

avoid duplicate data to be insert into database

9 views
Skip to first unread message

Jun Liu

unread,
Aug 22, 2001, 8:38:53 PM8/22/01
to
Hi,

I am developing an data entry page using ASP and SQL Server 2000.

In ASP page, there are 3 textboxes for user to enter data and insert into
database fields: taskno, taskdate, and taskdesc. In databse, it also has a
field: rec_no, which is primary key, and its 'identity' is 'yes', 'identity
seed' is '1', and 'identity increment' is '1'.

I don't want any duplicate record to be inserted into the database, is there
any way in ASP that I can avoid the duplicate data?

Their data types are below:

Column Name Data Type Length Allow Null
========== ======= ===== =======
taskno varchar 10 yes
taskdate datetime 8 yes
taskdesc varchar 255 yes
rec_no(Primary Key) int 4 No

Thanks.

Jun


D Dierking

unread,
Aug 23, 2001, 2:20:56 PM8/23/01
to
You might try setting a unique index on the SQLServer table
with "ignore duplicate key" set. Duplicates are not added
and the system doesn't throw a fit and produce error
messages.
>.
>

Bob Milutinovic

unread,
Aug 23, 2001, 3:04:51 AM8/23/01
to
G'day, Jun...

Do you need each and every field to be unique, or just the record to be
unique?

If it's the first (every field unique), try this:

<%
'assume cDB is your database connection and is already open
sTaskNo = Request.Form("TaskNo")
sTaskDate = Request.Form("TaskDate")
sTaskDesc = Request.Form("TaskDesc")
sQuery = "SELECT Rec_No FROM tTable WHERE" & _
"TaskNo='" & sTaskNo & "' OR " & _
"TaskDate='" & sTaskDate & "' OR " & _
"TaskDesc='" & sTaskDesc & "'"
set rsDB = cDB.Execute(sQuery)
if rsDB1.EOF then
'insert the data here...
else
Response.Write "Hey! It's a duplicate!"
end if
%>

If it's the second (unique records), use this:

<%
'assume cDB is your database connection and is already open
sTaskNo = Request.Form("TaskNo")
sTaskDate = Request.Form("TaskDate")
sTaskDesc = Request.Form("TaskDesc")
sQuery = "SELECT Rec_No FROM tTable WHERE" & _
"TaskNo='" & sTaskNo & "' AND " & _
"TaskDate='" & sTaskDate & "' AND " & _
"TaskDesc='" & sTaskDesc & "'"
set rsDB = cDB.Execute(sQuery)
if rsDB1.EOF then
'insert the data here...
else
Response.Write "Hey! It's a duplicate!"
end if
%>

- Bob.


"Jun Liu" <jl...@adscon.com> wrote in message
news:ebQrRv2KBHA.1072@tkmsftngp02...

0 new messages