1

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".

2
  • Could you show the format for what the file is supposed to look like related to the SQL server? Commented Nov 24, 2011 at 21:31
  • Please note that Batch tag is "used for Windows batch file questions". Don't use it just because your question is related to "batch" word in any way... Commented Nov 25, 2011 at 2:39

4 Answers 4

2

You can import in fully managed code via SqlBulkCopy; all you need to do is pass SqlBulkCopy an IDataReader that handles TSV. Fortunately the FastCsvReader on codeproject can do exactly that.

Sign up to request clarification or add additional context in comments.

1 Comment

I have some trash rows in my file. I need something like row patterns (Regex). I could create some file converter then use SQLBulk
1

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.

Comments

0

Sounds like a perfect job for SQL Server Integration Services (SSIS). You can easily define a data import task in SSIS and then schedule it to run by using a SQL job.

1 Comment

I'm using SQL Server 2008 express
0
bulk insert [dbo].[CoursesTemp]

from 'C:\Users\Public\Downloads\Courses.csv'

with (fieldterminator = ',', rowterminator = '\n')
go
insert [dbo].[Courses]
  (code, description, instructor, date, venue, duration)
select 
   code, description, instructor, cast(date as date), venue,
   duration
from [dbo].[CoursesTemp]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.