Solved

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

Posted on 2006-10-19
4
159 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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