I am still learning Classic ASP and SQL. I am trying to import data from a CSV file into a SQL 2005 table. The ASP page works fine until I try to upload the file. When I upload the file the first row of data is seen and held in the record set and then it produces this error message:
IMW-212932-AutoresponderIDs-201212.csv
EXECUTE ImportAutoresponderIDList_Insert @FileName = 'IMW-212932-AutoresponderIDs-201212.csv' , @"AutoresponderID" = '701488' , @"AutoresponderName" = 'Love - Upgrade - Bronze Package'
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'AutoresponderID'.
/admin/Spitfire/Import1SCExportFiles/ImportAutoresponderList.asp, line 107
I know the error is not in the ASP page as another import routine uses this same code with only the variable names being different AND because AutoresponderID is not mentioned in the ASP.
AutoresponderID is a field name in the SQL table and is mentioned in the stored procedure.
Where is the syntax error? Here is the stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ImportAutoresponderIDList_Insert]
@FileName varchar(255)
, @AutoresponderID int
, @AutoresponderName varchar(255)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO ImportAutoresponderIDList
(
[FileName]
, [AutoresponderID]
, [AutoresponderName]
)
SELECT
@FileName
, @AutoresponderID
, @AutoresponderName
END
Code Block From OPs Comment
Dim sqlImportAutoresponderIDListTemplate
sqlImportAutoresponderIDListTemplate = "EXECUTE ImportAutoresponderIDList_Insert" & vbCrLf
sqlImportAutoresponderIDListTemplate = sqlImportAutoresponderIDListTemplate & " @FileName = '" & SQLEncode(strFileName) & "'" & vbCrLf
arrColumnList(0) = "FileName"
Do While lngOffset < Len(strLine)
lngColumn = lngColumn + 1
lngLength = InStr(lngOffset, strLine, strColumnDelimiter)
If lngLength < 1 Then
lngLength = Len(strLine) + 1
End If
lngLength = lngLength - lngOffset
strColumn = Replace(Mid(strLine, lngOffset, lngLength), "/", "")
lngOffset = lngOffset + lngLength + 1
sqlImportAutoresponderIDListTemplate = sqlImportAutoresponderIDListTemplate & " , @" & Replace(strColumn, " ", "") & " = '[" & strColumn & "]'" & vbCrLf
arrColumnList(lngColumn) = strColumn
Loop
ElseIf lngLine > 1 Then
If strLine = "" Then
Exit Do
End If
Dim sqlImportAutoresponderIDList
sqlImportAutoresponderIDList = sqlImportAutoresponderIDListTemplate
Do While lngOffset < Len(strLine)
lngColumn = lngColumn + 1
strColumn = ExtractColumn(strLine, lngOffset, strColumnDelimiter)
If Left(strColumn, 1) = """" Then
strColumn = Mid(strColumn, 2, Len(strColumn) - 1)
End If
If Right(strColumn, 1) = """" Then
strColumn = Mid(strColumn, 1, Len(strColumn) - 1)
End If
sqlImportAutoresponderIDList = Replace(sqlImportAutoresponderIDList, "[" & arrColumnList(lngColumn) & "]", Replace(strColumn, "'", "''"))
Loop
Dim rsImportAutoresponderIDList
Set rsImportAutoresponderIDList = CreateObject("ADODB.Recordset")
Response.Write "<p>" & sqlImportAutoresponderIDList & "" & vbCrLf
rsImportAutoresponderIDList.Open sqlImportAutoresponderIDList, Application("DATABASE_Name")
Set rsImportAutoresponderIDList = Nothing
End If
[Edit]Code block included from OPs Comment by Jibesh[/Edit]