Catching Errors (Exceptions) on AccessDataSource Insert Command

mountainbiking
02-21-2007, 06:56 AM
What is the best way to catch exceptions when you insert a record and there are error outside of what you have validated?

mountainbiking
03-05-2007, 04:51 AM
Help!!!

wayneph
03-05-2007, 08:09 AM
I think you're going to need to be a bit more specifc. Here is a basic tutorial that deals with the ObjectDataSource, but it could be helpful with the SQLDataSource as well: http://www.asp.net/learn/dataaccess/tutorial38vb.aspx?tabid=63.

Also, down the Right Side of the page there are quite a few other tutorials that may help with other Data questions.

mountainbiking
03-06-2007, 09:05 AM
Ok, let me give a little more info... if I have a user creating a record by using a formview and they enter required information and everything is in the allowable limits as set by various validation control... but when the user clicks submit (the insert command is tied to AccessDataSource2) and they generate the following error:

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

This can happen frequently because various people enter information at the same time, so somebody may have already entered a record w/the same quote ID.

How can i trap this error and display my own custom message as to why they received the error so they know what to go back and fix?

wayneph
03-06-2007, 10:19 AM
Why would this happen frequently? I'd have an AutoNumber in the database assigned when the record is inserted. You shouldn't have the clients inserting this. In the worst case, you should look up the next value at the point when you're saving. Not a few minutes ahead of time.

A true ID in the database should be assigned by the system and irrelavent to the user. They shouldn't have to be the one that fixes it.

mountainbiking
03-06-2007, 11:03 AM
I have the AutoNumber set up... that is the true ID field in this specific table... The user enters a County Code and a Location code...

For example, if you have a County Code of 0100 and you have Locations within 0100 of 0001 to 0200 you cannot have a duplicate of any location code within the same County Code...

This is what I was getting at... I have the proper field set to Not Allow Duplicates... when duplicates are entered I get the code I displayed... I know how to display the code for the Ex.Exception.Message, I want to identify the error type then place my own friendly error message against it.

wayneph
03-06-2007, 01:46 PM
Take a look at the SqlDataSource.Inserted event. The exception is passed to the EventArgs and you can work with it there.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum