Solved

vb.net sql command error

Posted on 2004-08-25
5
232 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
Comment Utility
Perhaps try:
For t = 0 To records.Length - 1

0
 

Author Comment

by:bear23
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now