Search code examples
c#sql-serverfile-import

Import flat file to SQL server using C#


I want to make a program in C# that imports two types of files to SQL Server: tab delimited and fixed columns. Actually, I need to download a file every day and import that file into my database. I could make a console app with batch script. I saw some examples like this, but I don´t know if it is the best object-oriented way to do it.

I could use StreamReader, Regex and so on, but I don't want to re-invent the wheel.

PS: In VBA I used "QueryTables.Add".


Solution

  • If you don't want to reinvent the wheel, then you should look at the native tools that SQL Server provides for this, namely bcp. Here is a list of FAQs about bcp.