Sunday, August 29, 2004

 

CheckDuplicate in Dataset

Hi,

Say the dataset ("MyDataset") has a table ("MyTable") that has following data in one of the columns ("COL1"): 'a', 'b', 'c', 'd' and 'e' (5 entries, since there are 5 rows). Say the user enters a value 'a' in a text (txtValue) box and clicks submit. In the submit button's click handler, you have to do is this (in C#):

DataRow[] drArray = MyDataSet.Tables["MyTable"].Select("COL1 = " + txtValue.Text.Trim());

if(drArray.Length > 0) //User has entered a value that already exists in the dataset
{
//Display message
}
else //User has entered a unique value
{
//Proceed with further processing.
}

This code will not check for case-insensitivity, i.e., if the user enters 'A' instead of 'a', it will take it as a unique entry. You will have to add further checks to ensure case-insensitivity. Hope this helps.

Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?