1,105,546 Community Members

problem regarding insert into statement

Member Avatar
rishif2
Posting Whiz in Training
284 posts since Dec 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 4 [?]
 
0
 

hello experts . . .
i am using following code:-
con.Execute "insert into tbl values('" & Text1.Text & "','" & Text2.Text & "') ", adCmdText
i am trying to insert data using above statement and its working well but an error occures when i input data (contaning the symbol ' )

for example when i input qwe'r it will give an error

So Any Solution to do so . . .

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

The following should do the trick -

con.Execute "insert into tbl values('" & Replace$(Text1.Text, "'", "''") & "','" & Text2.Text & "') ", adCmdText

''Assuming that Text1 will return the apostrophe character...

''Note the double '' inside there to still make the sql work.
Member Avatar
rishif2
Posting Whiz in Training
284 posts since Dec 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 4 [?]
 
0
 

thanx , its working . . .

Question Answered as of 1 Year Ago by AndreRet
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Only a pleasure. Happy coding.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article