Check UNIQUE constraint name
// check UNIQUE constraint name int New Bll. Funcs (). GetRecordCount (string. Format ("name={0}", model. Name)); if (! Checkuniquefieldbycount (Editid, Count, Prename, model. Name) { FineUI.Alert.Show (Resources.WebResource.SaveFailed); return ; }
The new and edited unique validation is different and must be judged separately:
/// <summary> ///Check for UNIQUE constraints/// </summary> /// <param name= "Editid" >Edit ID</param> /// <param name= "Count" >the number of queries based on the current name</param> /// <param name= "Prename" >Original Name Value</param> /// <param name= "NewName" >New Name Value</param> /// <returns>is unique</returns> protected BOOLCheckuniquefieldbycount (intEditid,intCountstringPrename,stringnewName) { if(Editid >0) { //if the name already exists that is not itself if(Count >1|| (Count = =1&& NewName! =prename)) { return false; } } Else { //if the name already exists if(Count >0) { return false; } } return true; }
Determine if the unique constraint is unique