?
Solved

vb.net sql command error

Posted on 2004-08-25
5
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 140 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

770 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