Click here to Skip to main content
14,550,105 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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".
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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 />
}
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 5

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
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

I don't see why not. If it works for you, then use it.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100