StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Save after edit gives broken rules on...Expand / Collapse
Author
Message
Posted 06/22/2006 10:41:57 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame 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?
Post #1636
Posted 06/22/2006 10:49:40 AM


StrataFrame Developer

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

Post #1637
Posted 06/22/2006 11:24:11 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 3:40:41 PM
Posts: 328, Visits: 479
Thanks, that works great!
Post #1641
Posted 06/22/2006 11:38:33 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 2:14:29 PM
Posts: 4,901, Visits: 4,886
Good.  Glad to help
Post #1644
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 5:46pm

Powered by InstantForum.NET v4.1.4 © 2009
Execution: 0.125. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.