tags:

views:

169

answers:

2

I have validated the email but i need to check if email exists in database or not ? For Ex:

User has entered the new record with email. Next time he clicks on Datagridview and all the records are loaded in textboxes. Now He updates the email.Here it should again check if email exists.If not update the same Email.

Thank you

A: 

From the vague information you're giving I guess the following:

  1. The user adds a new record to a list of address records
  2. Before the record is added you're checking whether the email address is unique (which works => the record is added)
  3. When the user changes the record, the email check fails

I suppose that you fail to consider the case that you're comparing the same records. Assume the following:

  1. You have records A and B, which both have unique email addresses
  2. User enters new record, you validate eMail address C against A and B => unique, you add record C
  3. User modifies record C, you compare eMail address against all known records, so you compare eMail address C with A, B and C => Of course, the eMail address is already known.

You should modify your check so that the condition is: eMail address already exists if a record with the same eMail address is found and the record is not the same as the one being edited right now.

But again: The information you're giving is very vague - I might be far off the right track here...

Thorsten Dittmar
A: 

Here is my understanding of your question: You want to know how to test the email on the serverside before trying to commit the update/insert.

You can create a method to fire to do the update. Just put code in this method to check the database for the existance of the email. Here's a good example: [http://www.dotnetheaven.com/UploadFile/rahul4%5Fsaxena/TheBasicoperatoinofDataGrid04252007023744AM/TheBasicoperatoinofDataGrid.aspx%5D%5B1%5D

Go look at the updategrid_UpdateCommand method - that's where he's committing the data. Just put in a check to query the DB before committing. If it doesn't exist, let the commit happen, if it does (and the email address does not belong to the record being updated) then show a message to the user telling them what's wrong.

Cheers, Lance

Lanceomagnifico