Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Using vbscript i am trying to add data to access database. I am successfully able to add data to database but i want to check duplicity before adding data to database.

Duplicity should check in column Name, Phone and Id if found duplicity in any of these three column then show message found duplicity.

Below is the code which help me to add data to database.

sub addUser
    SQL_query = "INSERT INTO dvd (timestammp,Name,Phone,Id,Cat,StartDate,agent,amount,source,conver) VALUES ('"& txtteNow.value &"','"& txtName.value &"','"& txtPhone.value &"','"& txtId.value &"','"& txtCat.value &"','"& txtStartDate.value &"','"& txtsrch.value &"','"& txtamount.value &"','"& txtsource.value &"','"& txtconver.value &"')"
    conn.Execute(SQL_query
end sub 

I try below code also but not working.

SQL_query = "INSERT INTO dvd (timestammp,Name,Phone,Id,Cat,StartDate,agent,amount,source,conver) VALUES('"& txtteNow.value &"','"& txtName.value &"','"& txtPhone.value &"','"& txtId.value &"','"& txtCat.value &"','"& txtStartDate.value &"','"& txtsrch.value &"','"& txtamount.value &"','"& txtsource.value &"','"& txtconver.value &"') WHERE NOT EXISTS (Select '2' from dvd  where Name = + " & txtName.value & + "
conn.Execute(SQL_query)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
195 views
Welcome To Ask or Share your Answers For Others

1 Answer

Why don't you just try adding Unique Indexes to Name, Phone and Id ? This way the database engine will discard those records automagically.
Possible drawback: you will not know which record has been dropped.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...