Active Server Pages Programming (ASP)/Error Number
Expert: Srini Nagarajan - 5/13/2005
Question-------------------------
Followup To
Question -
Unique key constraint set in a table of SQL Database. When user attempt to save a record by adding or editing with the duplicate key; an message box should come on page indicating that id is already present in table (as per error number error handling). Please guide me.
Thanks in advance.
Regards
Answer -
Hi
Before saving the entry.. You have to check whether that key exsits in the database using
select count(key) from tablename where key = inputkey
if you get 0(zero) means key not exists otherwise key exists...
Happy Programming!!
-srini
Thank you very much for your quick and workable reply but; sir one thing is that if there is already id is in table a message box should come with messaging "id is already in table. Do you want to correct it or cancel." I m not able to get a message box.
Please favour me.
AnswerHi
Here is the workflow
if someinput = "1"
overwrite / or update
end if
IF count = 0 then
insert
else if
<script>
var sval = confirm("found overwirte")
if (sval)
document.form.someinput.value = "1"
document.form.submit
</script>
end if
Happy programming!
-srini