Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a console application which must generate reports according to the data in mysql(write the report according to the email column). What i want to do is, populate a datatable with the one entire column. Then, the program should loop through the datatable. And add every email it comes accross to another table i created in mysql. But it must verify that the email it is adding is not already in the database. So it should check the database before just adding data.

Could i ask anyone for help on this?

Thank you in advance.
Posted
Comments
wizardzz 6-Dec-10 17:38pm    
Just a quick question, why are you using 2 datatables for this?
WynandS 7-Dec-10 2:15am    
Well not that i want to use two tables. I am working for a company, and our client has two tables.
So it is not by choice.

You can try before inserting a record for checking whether the specific record-email is already been there or not.

SQL
select cout(emailid) where emailid='xyz@abc.com'
or
select * where emailid='xyz@abc.com'


if retrieved query result contains any row then you must not insert the record with that email id as its already present.
 
Share this answer
 
v2
Another way is to:
SELECT DISTINCT email FROM tablename

This will return a unique list of the email addresses in the table and prevent having to loop through results.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900