views:

316

answers:

3

How can I run the Bulk Copy Program (BCP) utility of SQL Server through .Net code?

+2  A: 

Take a look at the SqlBulkCopy class. And there's another article with examples.

Andomar
This will only let you INSERT data, not export it.
thomasnguyencom
+1  A: 

You can execute this SQL command in a Command object

BULK INSERT <TableName> from '<FileName>' with (FORMATFILE='<FmtFile>')

Replacing the items in angle brackets with proper item names

Binary Worrier
A: 

Here are some possible options:

  1. From .NET 2.0, we can use SqlBulkCopy class
  2. Use BULK INSERT Query
  3. Use an integration service package (SISS).

...and

  1. If you still need bcp utility, then you can run it as a process... which I will reccomend less.
NinethSense