| | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: Today @ 3:40:41 PM Posts: 328, Visits: 479 |
| | I have a user control which is basically like the maintenance tool strip. It has save, new, delete, edit, and undo buttons which function on a business object and linked to controls on the form. I have some business rules setup which prevent duplicate names from being entered into the database. This works perfectly when doing a New operation and saving. However, if I edit a record and then try to save it will give me a broken rule for things that haven't changed. For example, I have a FirstName and a LastName field. I want to only edit the FirstName, but leave the LastName alone. If I do this, and then save it will give me a broken rule on LastName if I'm not allowing duplicates. Is there some way around this? Maybe a setting that tells the BO not to check rules on fields that haven't changed from their original state? |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 2:14:29 PM Posts: 4,901, Visits: 4,886 |
| | Andria, Your business rule needs to exclude the record your are working on. The best way to do this is include the primary key as part of the test. This will work for new or existing records. Example: '-- Establish Locals Dim loCommand As New SqlCommand() '-- Build the command loCommand.CommandText = "SELECT COUNT(*) FROM MyTable WHERE mt_pk != @mt_pk AND mt_lastname = @mt_lastname" '-- Add the parms loCommand.Parameters.Add("@mt_pk", Data.SqlDbType.Int) loCommand.Parameters.Add("@mt_lastname", Data.SqlDbType.VarChar) '-- Set the parms loCommand.Parameters("@mt_pk").Value = PassedPrimaryKey loCommand.Parameters("@mt_lastname").Value = PassedLastName
'-- Return Boolean Results Return CType(Me.ExecuteScalar(loCommand), Integer) > 0 |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: Today @ 3:40:41 PM Posts: 328, Visits: 479 |
| | Thanks, that works great! |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 2:14:29 PM Posts: 4,901, Visits: 4,886 |
| Good. Glad to help |
| |
|
|