• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

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

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
Johnny
Asked:
Johnny
  • 2
1 Solution
 
gangwischCommented:
normally you use '' instead of ' so the way to correct is:
insert into customers (fname,lname) values ('john','" & replace(lname,"'","''") & "')"
0
 
JohnnyAuthor Commented:
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
 
Mohamed ZedanCommented:
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
 
JohnnyAuthor Commented:
Thank you
0

Featured Post

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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now