Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when importing data from text file i want to update database table with new records(old + new records) and count the no of new records imported from textfile in C# windows form application.

I don't want to import records which are already present in database.

No primary key constraint in database table.

can any one help me to solve this problem.



Thanks.
Posted
Updated 4-Jun-14 23:53pm
v2
Comments
Herman<T>.Instance 5-Jun-14 5:55am    
Create a copy of the file in which you append a hashvalue based on the contents per line. If you store the hashes in your DB you can see which are new
Karthik Achari 5-Jun-14 6:39am    
Can you help me how to append hash value in to database because i am a begineer to database and C#
Thanks for your valuable suggestion
Herman<T>.Instance 5-Jun-14 8:04am    
make one long string from all fields in a datarow. Calculate the hash over this string and store it somewhere.
[no name] 5-Jun-14 6:11am    
You have not described any problem as yet. All you have described so far is some work you need to do.
Karthik Achari 5-Jun-14 6:15am    
i am importing data from text file and updated in the grid view and database but i want to know how many new records are imported(irrespective of old records)
Thanks

1 solution

1. Load the txt into a temporary table.

2. Use the "except" key word in sql server to get the records which are not existing in Actual table and existing in Temporary table.
e.g.
SQL
Select col1,col2, col3 from ActualTable
          Except
Select col1,col2, col3 from TemporaryTable



3. Then insert the resultant records of step 2 into ActualTable.
 
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