i have written a stored procedure for bulk insert like this:
我已经为批量插入编写了一个存储过程,如下所示:
USE [BRDCEP_MIS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc dbo.SP_BulkInsertPsc
as
begin
BULK INSERT BrdcepPscData
FROM 'E:\BRDCEP_MIS\BRDCEP_MIS\App_Data\PSC\NRSP.csv'
WITH
(
FIRSTROW = 2 ,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
end
GO
and i want to execute this SP when i call the specific function in the controller it shows no error but also it is not adding data into the database . my controller function is this:
我想在控制器中调用特定功能时执行此SP,它没有显示错误,但也没有将数据添加到数据库中。我的控制器功能是这样的:
[HttpGet]
public ActionResult ImportPSCData()
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
db.Database.ExecuteSqlCommand("TRUNCATE TABLE BrdcepPscData");
var a = db.Database.SqlQuery<int>("Sp_BulkInsertPsc");
}
return View();
}
can anybody please tell me what i am doing wrong?
任何人都可以告诉我我做错了什么?
1 个解决方案
#1
0
If you are trying to upload data to your SQL server as a one-off, you can use the Sql Server Import Wizard.
如果您尝试将数据作为一次性上载到SQL服务器,则可以使用Sql Server导入向导。
If you are creating an application that features a bulk-upload facility, you can use the Bulk Copy Class. This allows you to map columns in your SQL database to a .CSV file.
如果要创建具有批量上载工具的应用程序,则可以使用批量复制类。这允许您将SQL数据库中的列映射到.CSV文件。
#1
0
If you are trying to upload data to your SQL server as a one-off, you can use the Sql Server Import Wizard.
如果您尝试将数据作为一次性上载到SQL服务器,则可以使用Sql Server导入向导。
If you are creating an application that features a bulk-upload facility, you can use the Bulk Copy Class. This allows you to map columns in your SQL database to a .CSV file.
如果要创建具有批量上载工具的应用程序,则可以使用批量复制类。这允许您将SQL数据库中的列映射到.CSV文件。