Computing.Net > Forums > Programming > insert in VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

insert in VB

Reply to Message Icon

Name: sunny
Date: October 8, 2004 at 09:10:56 Pacific
OS: xp
CPU/Ram: 256
Comment:

hi ,
i got porblem when iam trying to insert a string having an apostrophy (') into SQL Server 2000 from VB ..
i.e the VB statement is :
cn.open "insert into table1 values('"str"')"

here my str=Raja's
iam getting error with this syntax..
if str=Rajas
it dosent give error.

some one pls tell me how to insert strings like the previous one..



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: October 8, 2004 at 10:28:28 Pacific
Reply:

before using any strings in a query with sql server, replace any instances of ' with ''.

str = replace(str, "'", "''")

Good luck,
-SN


0

Response Number 2
Name: sunny
Date: October 9, 2004 at 04:36:02 Pacific
Reply:

thank u for your suggestion SN but it dosent work. if i make it double qoutes it is entering double quotes not ' .
pls any one tell me how to insert (') into the data base ( sql server ).
thank u .


0

Response Number 3
Name: SN
Date: October 9, 2004 at 08:57:02 Pacific
Reply:

Sunny-
Sorry my suggestion didn't work. I'm quite certain that is how you do it though...Try running the query manually in Server
Enterprise Manager or Query Analyzer:

INSERT INTO tbl (field1) VALUES ('don''t eat yellow snow')

and see if it puts in the single apostraphe. If it doesn't, perhaps there is some setting in SQL server that needs to be changed. If it works, then something is going on in your code (maybe accidentally performing the replace twice on the same string?)

Luck,
-SN


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Free Server? Free Visual COPY command in DOS



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: insert in VB

Autocad Insert In VB form www.computing.net/answers/programming/autocad-insert-in-vb-form/9161.html

On Error in VB www.computing.net/answers/programming/on-error-in-vb/9139.html

need help in vb www.computing.net/answers/programming/need-help-in-vb/9854.html