Solved

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

Posted on 2004-03-27
9
338 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
[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
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
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 …

734 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