Message
From
23/06/2008 17:35:49
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
New to MM.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01326209
Message ID:
01326209
Views:
76
Hi,

I am very new to the MM .NET framework and just working through the learning curve.

I am looking for the best method to enforce a unique constraint on a table. I have set up a unique constraint on a varchar field in my table and then used the MM Business Object Wizard to model the table into classes. I can find the validation code for the table, but do not see any code where the framework checks back against the SQL table for uniqueness before attempting the save. When I test the code, I get an exception thrown when the SQL insert statement fails because of the SQL constraint, but I would like to test prior to the statement failing and return something other than a cryptic SQL error to the user.

Inside my validation rules I would like to excute a statement or stored procedure something like the following:

SELECT COUNT(*) AS DupCount FROM MyTable WHERE UniqueColumn = @NewValue

If the count is greater than one, I can send the user a polite "Pick Another Value" message.

Again I am new to MM.NET so I am sure I am just missing something simple, but any help pointing me in the right direction would be appreciated.

Thanks in advance.

Tim Holgerson
Next
Reply
Map
View