trying to bulk insert a csv file into my SQL database from an asp.net vb web app/form page that the user uploads, my problem is that im new to all this and although the SQL statement inserts the CSV within my SQL Query analyser it comes up with this error in the actual app when trying to run it, ive probably done this wrong so can someone look at the error and my code and point me in the right direction
Server Error in '/MerlinLocalPost OfficeApp' Application.
--------------------------------------------------------------------------------
Incorrect syntax near '('.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Sql Client.SqlExcep tion: Incorrect syntax near '('.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
Source Error:
Line 64: cmdInsert = New SqlCommand(strI nsert, SQLConn)
Line 65: SQLConn.Open()
Line 66: cmdInsert.Execu teNonQuery()
Line 67: SQLConn.close()
Line 68: End Sub
Source File: c:\inetpub\wwwr oot\MerlinLocal PostOfficeApp\A dministrator\Up loadFinal2.aspx Line: 66
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near '('.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.]
System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) +857338
System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) +734950
System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) +188
System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) +1838
System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async) +192
System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) +380
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +135
ASP.administrat or_uploadfinal2 _aspx.ImportBut ton_Click(Objec t sender, EventArgs e) in c:\inetpub\wwwr oot\MerlinLocal PostOfficeApp\A dministrator\Up loadFinal2.aspx :66
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +105
System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String eventArgument) +107
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +7
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +5102
heres my code
Expand|Select|Wrap|Line Numbers
- Sub ImportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim SQLConn As New System.Data.SqlClient.SqlConnection
- SQLConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PostOffice.mdf;Integrated Security=True;User Instance=True"
- Dim strInsert As String
- Dim cmdInsert As SqlCommand
- strInsert = "BULK INSERT LocalPostOffice FROM()'c:\Inetpub\wwwroot\MerlinLocalPostOfficeApp\Data\csv.txt' WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', TABLOCK)"
- cmdInsert = New SqlCommand(strInsert, SQLConn)
- SQLConn.Open()
- cmdInsert.ExecuteNonQuery()
- SQLConn.close()
- End Sub