I’ve a text file containing record of a dump of database table in a custom format, this text have a character in a specific position that identifies the operation with the record :
- M = Insert or Update
- D = Delete Record
Therefore if i find a D record in text file i need to delete record into database, instead if i find an M record i need to Insert the record if not exist in the database, if already exist i need to update it.
What is the better and fastest way to import a similar text file in a database table using .NET Framework and c#?
I have 300000 record of average in this text file.
Thanks
The easiest way is probably to use ADO.NET to create a typed datatable to load the data into and set the datarowstate accordingly, then flush the data via a DataAdapter.
The fastest way is probably creating a bulk SQL-Script to execute. LinQ can save you a lot of time when selecting the data (you can probably transform it on the fly).
There are also platform specific solutions that should be considered. See here a bulk insert for SQLServer.
http://dotnetslackers.com/Community/blogs/xun/archive/2008/04/15/sql-bulk-insert-and-ado-net-sqlbulkcopy.aspx