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 '/MerlinLocalPostOfficeApp' 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.SqlClient.SqlException: 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(strInsert, SQLConn)
Line 65: SQLConn.Open()
Line 66: cmdInsert.ExecuteNonQuery()
Line 67: SQLConn.close()
Line 68: End Sub
Source File: c:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Admini strator\UploadFinal2.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.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +857338
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +734950
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.RunExecuteNonQuer yTds(String methodName, Boolean async) +192
System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +380
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
ASP.administrator_uploadfinal2_aspx.ImportButton_C lick(Object sender, EventArgs e) in c:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Admini strator\UploadFinal2.aspx:66
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +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