Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

i am modifying my question with simple description

I am creating a website, in my database i have a table in which one of the column is unique identifier. So from webpage when ever i am inserting duplicate values in that column its throwing an exception in Data access Layer. so i want to catch this exception in my web form as well as i want to display the error message as "can not insert duplicate values." in the webpage.


Regards,
srikar
Posted
Updated 10-Dec-09 6:00am
v3

I'm sorry, what's your question? What you have described is a little unclear. Please update your question to make it more clear, making sure to describe exactly the problem you are having and what your actual question is.
 
Share this answer
 
Catch the exception in your code (VB? C#?) using a try/catch block. Then set the text of a label to "Cannot insert duplicate values".
 
Share this answer
 
try <br />
{<br />
<br />
   /// do your insert here<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
   // set the friendly error here:<br />
   lbError.Text = " ... no duplicates";<br />
   return;<br />
<br />
}
 
Share this answer
 
v3
can i use my code like this ?

Try
l_Database.gp_BeginTransaction()

ls_SqlStr = "insert into mst_country(cn_sid, cn_name) values("
ls_SqlStr = ls_SqlStr + "'" + po_Country.cn_sid + "', "
ls_SqlStr = ls_SqlStr + "'" + po_Country.cn_name + "') "

l_Database.gp_ExecuteQuery(ls_SqlStr)

l_Database.gp_CommitTransaction()

Catch SQLexc As SqlException
ls_ErrMsg = ls_ErrMsg + SQLexc.ToString()
Try
Catch exc As Exception
If InStr(1, SQLexc.ToString(), "UNIQUE KEY constraint") > 0 Then
o_General.lp_AddPipe(ls_ErrMsg)
ls_ErrMsg = ls_ErrMsg + "Can not insert duplicate values."
End If
End Try
l_Database.gp_RollbackTransaction()
Finally
l_Database.gp_CloseConnection()
l_Database = Nothing
End Try
 
Share this answer
 
I don't see why not. If it works for you, then use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900