Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello guys
I have two table
one is main table and
second is DNC.
In main table I have 5 columns...id,name,phone_number,address,city
In DNC table I have only one column that is phone_number.

I have to do.....match two table and remove data from main table which is presented in DNC.....using asp.net
please help me....
Posted
Comments
CHill60 25-Nov-15 6:08am    
What have you tried?
Do you really mean "duplicate rows" - it sounds like you want to remove data from one table if it exists in another table - that is a very different thing to removing duplicates
aarif moh shaikh 25-Nov-15 6:09am    
user sub-query for it..

Try
C#
public static void DeleteDuplicateEntry()
     {        
         using (SqlConnection cn = new SqlConnection("YourConnectionStringName"))
         {
             SqlCommand objComm = new SqlCommand("delete from MainTable where phone_number in (select phone_number from DNC)", cn);
             objComm.CommandType = CommandType.Text;
             cn.Open();
             objComm.ExecuteNonQuery();
         }         
     }
 
Share this answer
 
As you have said "remove data" - if you do not want to delete the entire row, but just remove the phone number from the Main table then replace the query in the SqlCommand with
SQL
update Main SET phone_number = '' FROM main INNER JOIN DNC on Main.phone_number = DNC.phone_number
 
Share this answer
 
Comments
Member 11874141 30-Nov-15 1:22am    
dear i want delete that row... not a specific column
CHill60 30-Nov-15 4:14am    
That's fine - use solution 1 in that case. I only posted this alternative as it wasn't clear from your post exactly what you wanted to do. To me "remove data" means "remove the content".

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