Solved

vb.net sql command error

Posted on 2004-08-25
5
235 Views
Last Modified: 2010-04-17
I have a sql command that I get an error on the last entry my code looks like this



I get this error: on the last record only (it doesn't matter what it is. Now if I would take the last record and move it to the first it doesn't do it, but now the record I switch does it. So it is doing to the last record regardless of what the actual data is.)

Error: Synatax Error in string in query expression "

My code:
records is an array

                For t = 0 To records.Length
                    realdata= records(t)
                    command.CommandText = ""
                    command.CommandText = "Insert into table1(field1) values ('" & Replace$(realdata, "'", "''") & "')"
                    command.Connection = con
                    command.ExecuteNonQuery()
                next i


now the reason I have the replace function is because I have some ' in my data.

Now I eliminated the errors for the first couple of records, but everytime it hits the last record it gives me that error again. I used a debug.write(command.commandtext) and it looks like the insert line isn't putting in the ') at the end of the sql command.


so that is probrably what is wrong, but I cannot figure it out. Any ideas

why just the last record, any other ideas???

this is vb.net
0
Comment
Question by:bear23
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:adefwebserver
ID: 11894502
Perhaps try:
For t = 0 To records.Length - 1

0
 

Author Comment

by:bear23
ID: 11894545
no the array is reading fine

for so reason the insert line for the last record is leaving out the ')



and giving me that error

each line seems to work until it gets to the last record and then nothing

when I used debug the only thing I can see that is missing is the ') on the last record.

I even tried to manually enter it and nothing.


0
 
LVL 3

Expert Comment

by:adefwebserver
ID: 11894624
I would simply output the results of my "Replace$(realdata, "'", "''")" function so that I can see what data is causing it to crash.
0
 

Author Comment

by:bear23
ID: 11894663
I did:

>>>>>when I used debug the only thing I can see that is missing is the ') on the last record.



0
 
LVL 3

Accepted Solution

by:
adefwebserver earned 35 total points
ID: 11894774
I've had problems where there were control characters in my string. I think you have a "line feed" that is causing the last  ') not to appear.

Perhaps this will help:
http://www.vbcode.com/asp/showsn.asp?theID=4472
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# code editing and collaboration 3 131
Turning python script into an applet 12 116
Beginner to Unreal Engine 4 5 94
ASP/VB email question 4 46
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question