Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > How to Insert Character ( ' ) in Access


Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2006, 12:39 AM
Kashif's Avatar
Kashif Kashif is offline
Junior Contributor
 
Join Date: Aug 2002
Location: Earth
Posts: 344
Default How to Insert Character ( ' ) in Access


Hi All Members.

I'm Using Execute Method to Insert Values from Vb 6.0 Interface into Microsft Access Database.

I want to ask if User TYPE ( ' ) Character in a Chracter type Field. How do i Insert that Value in the Database Using the Execute Method of a Connection Type Object.
__________________
Regards,
Kashif

There are too many Question that looks Odd
But it helps more to Learn
Reply With Quote
  #2  
Old 11-28-2006, 12:48 AM
gb711825's Avatar
gb711825 gb711825 is offline
Contributor
 
Join Date: Apr 2004
Location: Ireland
Posts: 563
Default

Look for Chr(39) in your textbox

Or just refer to the textbox in your SQL statement. It should not matter what the contents of the textbox is.
Code:
strInsert = "INSERT INTO [i]Table[/i]([i]field[/i]) VALUES( '" & me.Textbox & "')" cn.execute strInsert
__________________
Yeah Boyieeeeeeeeeee!
Reply With Quote
  #3  
Old 11-28-2006, 12:56 AM
jutsu's Avatar
jutsu jutsu is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 343
Default

You have to replace the (') with ('') or otherwise you'll get an error..
Code:
Dim a As String a = "'mama" a = Replace(a, "'", "''")
Reply With Quote
  #4  
Old 11-28-2006, 12:56 AM
Kashif's Avatar
Kashif Kashif is offline
Junior Contributor
 
Join Date: Aug 2002
Location: Earth
Posts: 344
Default

Here is my SQL Statment
Code:
mySQL = "INSERT INTO A_LVL2 VALUES (" & txtAcctCode & "," & "'" & txtDesc & "'" & "," & LVL1Code & ")" con.Execute (mySQL)
__________________
Regards,
Kashif

There are too many Question that looks Odd
But it helps more to Learn
Reply With Quote
  #5  
Old 11-28-2006, 01:05 AM
Kashif's Avatar
Kashif Kashif is offline
Junior Contributor
 
Join Date: Aug 2002
Location: Earth
Posts: 344
Default

Quote:
Originally Posted by jutsu
You have to replace the (') with ('') or otherwise you'll get an error..
Is there no Way to Insert Single Quote in the Database. because this the Requirement.
Replacement is not the Solution.
__________________
Regards,
Kashif

There are too many Question that looks Odd
But it helps more to Learn
Reply With Quote
  #6  
Old 11-28-2006, 01:07 AM
NEOLLE's Avatar
NEOLLE NEOLLE is offline
fully realized avatar

Super Moderator
* Expert *
 
Join Date: Jun 2004
Location: Davao Philippines
Posts: 2,295
Default

Just apply jutsu's recommendation

Code:
mySQL = "INSERT INTO A_LVL2 VALUES (" & txtAcctCode & ",'" & Replace$(txtDesc,"'","''") & "'," & LVL1Code & ")" con.Execute (mySQL)

Just a tip, its better to specify which the fields you will be inserting. This will cause an error if your database will be modified - like adding a new column, re-order the column assignment or a column is removed.
Reply With Quote
  #7  
Old 11-28-2006, 01:08 AM
jutsu's Avatar
jutsu jutsu is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 343
Default

That will insert only a single (') not (''). Try it first..
Reply With Quote
  #8  
Old 11-28-2006, 01:15 AM
gb711825's Avatar
gb711825 gb711825 is offline
Contributor
 
Join Date: Apr 2004
Location: Ireland
Posts: 563
Default

Sorry guys, dont know what I was thinking there. Of course the single quote will cause an error and yes, you'll need the Replace(). :/
__________________
Yeah Boyieeeeeeeeeee!
Reply With Quote
  #9  
Old 11-28-2006, 03:16 AM
Kashif's Avatar
Kashif Kashif is offline
Junior Contributor
 
Join Date: Aug 2002
Location: Earth
Posts: 344
Default

Quote:
Originally Posted by jutsu
That will insert only a single (') not (''). Try it first..

Thank u jutsu. its Working and insertng Single (').
i was thinking that by Replacing it will Replace (') with (").

Thanks u again.
__________________
Regards,
Kashif

There are too many Question that looks Odd
But it helps more to Learn

Last edited by Kashif; 11-28-2006 at 03:31 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->