In asp.net(c#),i use linqtosql,In the table,i 've set property of a field Isunique to true.. when the same value inserted again,it shows error(exception) "Cannot insert duplicate key row in object 'dbo.student' with unique index",i need to catch the exception and display the error message.. How to handle sqlexception ? Thanks in advance...
+3
A:
In it's simplest form:
try
{
// Code to attempt insert
}
catch(SqlException ex)
{
// Get error from ex.Message and do something with it
}
ckramer
2010-06-15 16:43:32