Reputation: 1511
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.
Upvotes: 1
Views: 580
Reputation: 754268
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();
}
Upvotes: 1