Solved

Inserting ' into table from vb to access. (Urgent)

Posted on 2004-03-27
9
335 Views
Last Modified: 2010-04-17
Hi,
i am trying to insert a ' from a visual basci query into a table in access but getting systax error becase while building query v use ' as text container like in follwoing line.
plz help me out.


insert into tblStudent values( 1, 'Sachin's wife'); //error

insert into tblStudent values( 1, 'Sachin s wife'); //no error



is there any way to solve this problem easy & reliable.
plz help with some gud example of quotation
must be simple if u  have more than one solutions plz welcome
thankx
0
Comment
Question by:tomerps1
9 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10694290
insert into tblStudent values( 1, 'Sachin''s wife');
0
 

Accepted Solution

by:
nilesh_parmar earned 50 total points
ID: 10695646
try this function and call it  in query

 Public Function fixit(ByVal somestr As String) As String

        fixit = Replace(somestr, "'", "''")

    End Function

use it for ex

insert into tblStudent values( 1, fixit('Sachin's wife'));

i've worked with this and i m sure it will work.
0
 

Expert Comment

by:nilesh_parmar
ID: 10695656
its doing same as venkateshwarr wrote, anyway ..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:crazycomputers
ID: 10696605
Unless I'm mistaken, that should be:

insert into tblStudent values( 1, 'Sachin\'s wife');
0
 

Expert Comment

by:nilesh_parmar
ID: 10696867
sorry ,
it should be
 insert into tblStudent values(1,'fixit(Sachin's wife)');
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10701312
>> insert into tblStudent values(1,'fixit(Sachin's wife)');

Guess it'll definitely not work. You're not calling the fixit () function. You're putting it as a constant 'fixit(...). Might give an error after Sachin'....

Perhaps what you can try is either what crazycomputers sugessted or if that doesn't work, use another dummy character instead of ' and while reading from the database, check if its that character and display ' in its place.
0
 

Expert Comment

by:nilesh_parmar
ID: 10701570
i meant

insert into tblStudent values(1,'" & fixit(Sachin's wife) & "');
0
 
LVL 5

Expert Comment

by:crazycomputers
ID: 10704076
The \ is standard for escaping special characters in SQL expressions, but we all know how M$ violates standards.  '' might work, but I'd put my money on \'
0
 

Author Comment

by:tomerps1
ID: 10738726
Thankx Nitesh Parmar
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Plain Text Editor for iPad 6 105
SQL Insert parts by customer 12 51
Create .bat File 16 69
Java array 10 55
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

713 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