Can someone please review my code and see where I can be missing information. I get the following error:
Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character string ' )'. at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) at System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async) at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() at _Default.SaveTo Database(String SavePath) in C:\Inetpub\wwwr oot\Webfile1\De fault.aspx.vb:l ine 78 - Imports System.IO
-
Imports System.Data
-
Imports System.Data.SqlClient
-
Partial Class _Default
-
Inherits System.Web.UI.Page
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
End Sub
-
Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.Click
-
Dim SaveLocation As String = Server.MapPath("Data") & "\upload.txt'"
-
If UploadFile(SaveLocation) Then
-
'the file was uploaded: now try saving it to the database
-
SaveToDatabase(SaveLocation)
-
End If
-
End Sub
-
Private Function UploadFile(ByVal SavePath As String) As Boolean
-
Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
-
-
'Checking if the file upload control contains a file
-
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
-
Try
-
'checking if it was .txt file BEFORE UPLOADING IT!
-
'You used to upload it first...but the file could be a virus
-
If File1.FileName.EndsWith(".txt") = False Then
-
'The file is not the expected type...do not upload it
-
'just post the validation message
-
message.Text = "Please submit a text file."
-
Else
-
'The file is a .txt file
-
'checking to see if the file exists already
-
'If it does exist Deleting the existing one so that the new one can be created
-
If IO.File.Exists(SavePath) Then
-
IO.File.Delete(SavePath)
-
End If
-
-
'Now upload the file (save it to your server)
-
File1.PostedFile.SaveAs(SavePath)
-
-
'After saving it check to see if it exists
-
If File.Exists(SavePath) Then
-
'Upload was sucessful
-
message.Text = "Thank you for your submission"
-
fileWasUploaded = True
-
Else
-
'the file was not saved
-
message.Text = "Unable to save the file"
-
End If
-
End If
-
-
Catch Exc As Exception
-
'We encountered a problem
-
message.Text = Exc.Message + " " + Exc.StackTrace
-
End Try
-
Else
-
'No file was selected for uploading
-
message.Text = "Please select a file to upload"
-
End If
-
Return fileWasUploaded
-
End Function
-
-
Private Sub SaveToDatabase(ByVal SavePath As String)
-
Try
-
' and bulk import the data:
-
'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
-
'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
-
Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=sa;password=xxx;"
-
Dim results As New DataTable
-
-
Using con As New SqlConnection(connection)
-
con.Open()
-
-
' execute the bulk import
-
Using cmd As SqlCommand = con.CreateCommand
-
-
cmd.CommandText = "bulk insert dialerresults from '" & SavePath & "' " & _
-
"with ( fieldterminator = ',', rowterminator = '\n' )"
-
-
cmd.ExecuteNonQuery()
-
End Using
-
End Using
-
'Else
-
'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
-
'End If
-
Catch ex As Exception
-
message.Text = ex.Message + ex.StackTrace
-
End Try
-
End Sub
-
-
End Class
Here is the line of code in question:
cmd.ExecuteNonQ uery()
Is this not the correcy syntax?
43 8528
I have the following code - Imports System.IO
-
Imports System.Data
-
Imports System.Data.SqlClient
-
Partial Class _Default
-
Inherits System.Web.UI.Page
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
End Sub
-
Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.Click
-
Dim SaveLocation As String = Server.MapPath("Data") & "\upload.txt'"
-
If UploadFile(SaveLocation) Then
-
'the file was uploaded: now try saving it to the database
-
SaveToDatabase(SaveLocation)
-
End If
-
End Sub
-
Private Function UploadFile(ByVal SavePath As String) As Boolean
-
Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
-
-
'Checking if the file upload control contains a file
-
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
-
Try
-
'checking if it was .txt file BEFORE UPLOADING IT!
-
'You used to upload it first...but the file could be a virus
-
If File1.FileName.EndsWith(".txt") = False Then
-
'The file is not the expected type...do not upload it
-
'just post the validation message
-
message.Text = "Please submit a text file."
-
Else
-
'The file is a .txt file
-
'checking to see if the file exists already
-
'If it does exist Deleting the existing one so that the new one can be created
-
If IO.File.Exists(SavePath) Then
-
IO.File.Delete(SavePath)
-
End If
-
-
'Now upload the file (save it to your server)
-
File1.PostedFile.SaveAs(SavePath)
-
-
'After saving it check to see if it exists
-
If File.Exists(SavePath) Then
-
'Upload was sucessful
-
message.Text = "Thank you for your submission"
-
fileWasUploaded = True
-
Else
-
'the file was not saved
-
message.Text = "Unable to save the file"
-
End If
-
End If
-
-
Catch Exc As Exception
-
'We encountered a problem
-
message.Text = Exc.Message + " " + Exc.StackTrace
-
End Try
-
Else
-
'No file was selected for uploading
-
message.Text = "Please select a file to upload"
-
End If
-
Return fileWasUploaded
-
End Function
-
-
Private Sub SaveToDatabase(ByVal SavePath As String)
-
Try
-
' and bulk import the data:
-
'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
-
'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
-
Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=sa;password=xxx;"
-
Dim results As New DataTable
-
-
Using con As New SqlConnection(connection)
-
con.Open()
-
-
' execute the bulk import
-
Using cmd As SqlCommand = con.CreateCommand
-
-
cmd.CommandText = "bulk insert dialerresults from '" & SavePath & "' " & _
-
"with ( fieldterminator = ',', rowterminator = '\n' )"
-
-
cmd.ExecuteNonQuery()
-
End Using
-
End Using
-
'Else
-
'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
-
'End If
-
Catch ex As Exception
-
message.Text = ex.Message + ex.StackTrace
-
End Try
-
End Sub
-
-
End Class
-
and when I try to upload to the page that this references I get the following error:
Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character string ' )'. at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) at System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async) at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() at _Default.SaveTo Database(String SavePath) in C:\Inetpub\wwwr oot\Webfile1\De fault.aspx.vb:l ine 78
The line of code in question is this one:
cmd.ExecuteNonQ uery()
The syntax of the SQL query is correct. I'm not sure what I'm missing but there is something here that I must be missing. Can anyone offer any assistance?
tlhintoq 3,525
Recognized Expert Specialist
Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged
Frinavale 9,735
Recognized Expert Moderator Expert
I think your problem is on lines 75 and 76 in the above posted code: -
cmd.CommandText = "bulk insert dialerresults from '" & SavePath & "' " & _
-
"with ( fieldterminator = ',', rowterminator = '\n' )"
See Bulk Insert (Transact-SQL) for help with Bulk Insert.
-Frinny
Frinny,
I think that you're right but I have no idea what is causing the error. I understand that sometimes by having a single quotation mark that this is seen as a line break, I've tried manipulating this file in a lot of different ways and I don't see what I have to do to fix this. Can you give me any ideas as to what needs to be done here?
Thank you,
Doug
Frinavale 9,735
Recognized Expert Moderator Expert
Honestly, I've never used this command before.
I would refer to the link I posted for you to come up with an answer for you....if you scroll down there are examples of how use this SQL command. Maybe they can help you?
I'll ask the SQL experts to take a look at this.
-Frinny
Frinny,
If you take the sql bulk insert string as just a query, it works fine. I wrote that long before I started this quest. The query itself executes correctly. I'm pretty sure that it may be the syntax on how it's written and inserted into the asp.net code here for this page that is causing this problem. I'm just not sure where. If you could ask the experts, I'd greatly appreciate it.
Doug
Megalog 378
Recognized Expert Contributor
If it's a problem with the single quote being misinterpreted, you can always swap them with a unique character set while building the string, and then do a replace on it afterwards with the double quotes. I've used your post, with carats as the replaced character. - cmd.CommandText = Replace("bulk insert dialerresults from ^" & SavePath & "^ " & _
-
"with ( fieldterminator = ^,^, rowterminator = ^\n^ )","^","""")
This will return: - bulk insert dialerresults from "C:\Folder" with ( fieldterminator = ",", rowterminator = "\n" )
I tried with the carat's replacing the single quotes, and still get the same error:
Line 1: Incorrect syntax near '^'. Unclosed quotation mark before the character string '^ with ( fieldterminator = ^,^, rowterminator = ^\n^ )'. at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) at System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async) at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() at _Default.SaveTo Database(String SavePath) in C:\Inetpub\wwwr oot\Webfile1\De fault.aspx.vb:l ine 78
here's the line of code after I modified it:
cmd.CommandText = "bulk insert dialerresults from ^" & SavePath & "^ " & _
"with ( fieldterminator = ^,^, rowterminator = ^\n^ )"
Megalog 378
Recognized Expert Contributor
You need to add the replace function to that to swap the carats back to double quotes.
Look at the first code block from my last post.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Carl |
last post by:
Can you tell me what is wrong with this syntax ?
string select = "UPDATE .. " +
"(,,,,,,,
,,,,
,,, ,
, , ) " +
" VALUES
(@id,@clientid,@total,@tps,@tvq,@gtotal,@datefac,@datepay,
|
by: Mark Findlay |
last post by:
Hello Experts!
I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:
"Incorrect syntax near the keyword 'DEFAULT'"
The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
|
by: Iham Sheen |
last post by:
Hi,
When I click at the Update button to commit changes in a MxDataGrid, I get
the error message "Unclosed quotation mark ...." if there is a single quote
in any of the columns.
How can I work around this problem?
Thanks.
Iham
|
by: Sandesh |
last post by:
Hello All,
Me saying " has any body come across such error would be
underestimating".
Well I am getting a very peculiar and unique error "Line 1: Incorrect
syntax near 'Actions'."
Explaining you the scene is the following Stored Proc.
|
by: martin1 |
last post by:
I just use DataSet to bind DataSetGrid and display from SQL DB.
when starting run in Visual Studio 2005, get "Line 1: Incorrect syntax near
'1'" error message from below fill line,
objDataAdapter.Fill(objDataSet, "mindata")
any help is greatly appriciated.
| |
by: iporter |
last post by:
In the following code, the two Response.Write statements output exactly
the same - I can copy and paste both into Query Analyzer, and run them
fine. However, if I comment out line 3, the assignment of "SELECT
T..." to the variable query, the last line produces the error:
Line 1: Incorrect syntax near '<'.
Many thanks in advance for any...
|
by: roamnet |
last post by:
hi
i created database file with .mdf extention ,sql server as a source
and use grid view to display data
there're no problem in data retrieve and display,but i want to edit it
or insert new records
there is an error "Incorrect syntax near '-'.
Must declare the scalar variable "@UserName".
I worked out in design view,code is automatically...
|
by: arial |
last post by:
Hi,
I am getting this error message:
Incorrect syntax near the keyword 'where'.
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:...
|
by: =?Utf-8?B?QW5kcmV3?= |
last post by:
Hi,
What is wrong with this code ? I got this error:
" Line 1: Incorrect syntax near 'sp_Collect'. "
which appears at the last line when | call the cm.ExecuteScalar . The sp
takes an int ID and returns a string Data. Using the debugger, I see that the
value of ID is correct.
Is this a C# problem, or SQL Server 7 problem ?
|
by: karenkksh |
last post by:
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 the keyword 'user'.
Source Error:
Line 35: ...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |