UniqueValueValidatorBase Class
Description
The UniqueValueValidatorBase class is the base class for the OleDbUniqueValueValidator and SqlClientUniqueValueValidator classes. UniqueValueValidatorBase inherits the BaseValidator class and must be inherited, as demonstrated in the OleDbUniqueValueValidator and SqlClientUniqueValueValidator classes.
Properties & Methods
UniqueValueValidatorBaseThe UniqueValueValidatorBase class is the base class for the OleDbUniqueValueValidator and SqlClientUniqueValueValidator classes.
  • ConnectionString - The string used to connect to the database containing the table to check uniqueness against. This property is ignored if ConnectionStringKey is specified.
  • ConnectionStringKey - The key of the value in System.Configuration.ConfigurationManager.AppSettings used to connect to the database containing the table to check uniqueness against. This value is used when a value is specified for both ConnectionString and ConnectionStringKey.
  • ConnectionStringsName - The name of the connection string in System.Configuration.ConfigurationManager.ConnectionStrings used to connect to the database containing the table to check uniqueness against. This value is used even if a value is specified for ConnectionString and/or ConnectionStringKey.
  • FieldName - The name of the field in the table specified in TableName to compare uniqueness against.
  • TableName - The name of the table in the database that will be used for determining uniqueness.
  • FieldType - The datatype that determines what the generated sql query will look like.
Protected Function ValidationSql(ByVal value As String) As StringThis function returns a string containing an sql query to be used for validating the uniqueness of the passed value.
  • value - The value used in the sql query to validate uniqueness.
Public MustOverride Function FormatDate(ByVal value As DateTime) As StringThis function returns a date formatted for the selected database.
  • value - The DateTime value to be formatted.
Public MustOverride Function FormatTime(ByVal value As DateTime) As StringThis function returns a time formatted for the selected database.
  • value - The DateTime value to be formatted.
Public MustOverride Function FormatDateTime(ByVal value As DateTime) As StringThis function returns a date and time formatted for the selected database.
  • value - The DateTime value to be formatted.
Public MustOverride Function DoValidation(ByVal value As String) As BooleanThis function returns a boolean value indicating whether the value is unique.
  • value - The value which needs to be determined whether is unique.
Public Enum DBTypes As ByteAn enumeration used to determine what type of data the field in the database table contains.
  • Character - Used for text formats such as varchar, char, text, etc.
  • DateTime - Used for dates and/or times
  • NoQuotes - Used for formats that do not require additional formatting, such as numeric values
Source Code
UniqueValueValidatorBase.vb:

Remarks
Because the validation involves connecting with a database, the validation is only done server-side. I am currently working on finding a way to use AJAX and client callbacks to modify the control to allow more immediate validation.