Solved

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

Posted on 2004-03-27
9
313 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
 
LVL 5

Expert Comment

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

insert into tblStudent values( 1, 'Sachin\'s wife');
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 76
mapShare challenge 13 89
Magic Software info 18 125
detecting  the added row index in a datagridview 3 59
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…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …

911 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

19 Experts available now in Live!

Get 1:1 Help Now