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
Solved

problem with problem chr in string when trying to save data to firebird db, how to fix

Posted on 2006-10-19
4
160 Views
Last Modified: 2010-04-23
im trying to read the files on a disk and some of the file names have a ' in it like c:\ero'sfiles.txt this is creating a problem for saving this to a firebird db (sql). how do i fix this a replace chr? or a excape chr maybe?

whats the code needed to fix this pleae too

thank you in advance for and code and help you my provide
0
Comment
Question by:Johnny
  • 2
4 Comments
 
LVL 10

Expert Comment

by:gangwisch
ID: 17771200
normally you use '' instead of ' so the way to correct is:
insert into customers (fname,lname) values ('john','" & replace(lname,"'","''") & "')"
0
 

Author Comment

by:Johnny
ID: 17771328
im reading files of a directory and theres a ' in the path/name of the file its saving to the database...
as a result the saved string its creating a problem for firebird db to understand and crashing at that point..i was thinking of doing a regex on the string but i dont knjow how to fix the problem if it needs to add a chr or replace it or what to fix the sql saved data string (modding it to work correctly)

            ' process all files in folder first
            Dim arrFiles() As String = System.IO.Directory.GetFiles(path)
            For Each eleFile As String In arrFiles
                Label1.Text = eleFile.ToString
                InsertData(CreateFileInsertStatement(eleFile))
                FileCount = FileCount + 1
                Label2.Text = FileCount.ToString
                Application.DoEvents()
            Next
so i assume wed have to change the eleFile to be parsed with the ' chr this way correcting the problem, but as ive said im not sure if it needs to be replaced or added to excape the chr or what to fix the problem..imnot sure of the code on how to do that too.
0
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 500 total points
ID: 17773833
all you have to do is insert this line here :

 For Each eleFile As String In arrFiles
                Label1.Text = eleFile.ToString
                dim NewFileName as string = elefile.Replace("'","""")  ' <--------------New Line
                InsertData(CreateFileInsertStatement(NewFileName)) '<------------Editted line
                FileCount = FileCount + 1
                Label2.Text = FileCount.ToString
                Application.DoEvents()
            Next
0
 

Author Comment

by:Johnny
ID: 17777884
Thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Move a class from Solution Items to a project 2 32
Modal Popup Extender control 1 35
VB.NET 2008 Publish Error 2 32
Iteration Help (Asp.net VB) 5 24
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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