Hi!
I am completely stumped.
Currently, I am trying to make a script that puts a CSV file into a database table([Transactions].[dbo].[Payments]).
The script is:
fileName = “C:\\Users\\USER\\Downloads\\Payments-20210327_2214_MDT.csv”;
var qry = “DELETE FROM [Transactions].[dbo].[Payments]”;
sql.ExecSql(qry);
qry = "BULK INSERT [Transactions].[dbo].[Payments] "
+ “FROM '” + fileName + "’ "
+ "WITH "
+ "( "
+ "FIRSTROW = 2, "
+ "FIELDTERMINATOR = ‘,’, "
+ "ROWTERMINATOR = ‘\n’ "
+ ") ";
dlg.ShowMessage(qry);
sql.ExecSql(qry);
The qry is:
I keep getting the error:
Yet when I do the exact same code in SMSS:
DELETE FROM [Transactions].[dbo].Payments
BULK INSERT [Transactions].[dbo].[Payments]
FROM ‘C:\Users\USER\Downloads\Payments-20210327_2214_MDT.csv’
WITH (
FIRSTROW = 2,
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’ )
It runs with no issue.
Here is the contents of the CSV file.(I have removed all the sensitive data and replaced it with other numbers/letters) Payments-20210327_2214_MDT.zip (576 Bytes)
(I tried pasting the CSV data, but it deletes a lot of the commas…)
Does anyone know why this happens?
Thank you!