अब Google Groups, यूज़नेट फ़ोरम में नई पोस्ट करने या उसकी सदस्यता लेने की सुविधा नहीं देता है. हालांकि, यूज़नेट फ़ोरम में मौजूद पुराना कॉन्टेंट देखा जा सकता है.

avoid duplicate data to be insert into database

9 बार देखा गया
नहीं पढ़े गए पहले मैसेज पर जाएं

Jun Liu

नहीं पढ़ी गई,
22 अग॰ 2001, 8:38:53 pm22/8/01
ईमेल पाने वाला
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

नहीं पढ़ी गई,
23 अग॰ 2001, 2:20:56 pm23/8/01
ईमेल पाने वाला
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

नहीं पढ़ी गई,
23 अग॰ 2001, 3:04:51 am23/8/01
ईमेल पाने वाला
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 नया मैसेज