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
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...