Solved

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

Posted on 2006-10-19
4
156 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select all rows in datagridview 15 17
Form design in vb.net 7 16
Create XML 5 29
Unable  to create new object 9 16
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now