1

I'm a beginner in asp.net and write a web application. I have 100 million records in my server in a .csv file, and I write this query in SQL Server to import all that data:

BULK INSERT BpartyTEMP
FROM 'D:\bparty2.csv'
WITH(
   FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n',
   CODEPAGE = '1256'
);

But I want write that query directly in asp.net c# code, how can I write that? Thanks.

2
  • You just use your normal SqlConnection and SqlCommand ADO.NET components, and use this SQL as the CommandText for your command. Easy peasy.... Commented Aug 15, 2015 at 6:54
  • thanks my friend to answer my problem,please post your solution,@marc_s Commented Aug 15, 2015 at 6:55

1 Answer 1

1

You just use your normal SqlConnection and SqlCommand ADO.NET components, and use this SQL as the CommandText for your command.

string bulkInsertQuery = "(your BULK INSERT statement here)";

using (SqlConnnection con = new SqlConnection(-your-connection-string-here-))
using (SqlCommand cmd = new SqlCommand(bulkInsertQuery, con))
{
   con.Open();
   cmd.ExecuteNonQuery();
   con.Close();
}   
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.