Get SQL Error Number from OnInserted

Joined
Jun 12, 2010
Messages
2
Reaction score
0
I am trying to get the SQL Error number when inserting from a FormView/DetailsView, etc. Insert command. I can use the Inserted event on the datasource to check for an exception, but e only has e.message not e.number. I want to capture the number (e.g., 515) like you can when inserting directly with the datasource and catching SqlException. (SqlException exsql; int x = exsql.number;) Thanks
 
Joined
Jun 12, 2010
Messages
2
Reaction score
0
Of course after posting I found the solution.
using System.Data.SqlClient;

SqlException exsql = (SqlException) e.Exception;
lbl_Error.Text = MyNameSpace.TranslateError(exsql.Number);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top