?
Solved

quoted string not properly terminated

Posted on 2011-04-19
2
Medium Priority
?
756 Views
Last Modified: 2012-05-11
Have an excel file I am importing into an Oracle database using a small C# application only problem is that if someone sticks an apostrophe in there it kills the entire process. I am doing an insert to a temp table and then using a package to do the final insert.  Suggestions?

below is where I am parsing through the excel. The issue happens with the comments column.
 
while ((line = sr.ReadLine()) != null)
                {
                    cnt2 += 1;
                    row = line.Split(',');
                    ExternalAcct = row[2];
                    FirstCompDate = row[3];
                    LastCompDate = row[4];
                    CompCode = TranCompCode(row[5]);
                    Comments = row[20].Replace("'","");

                    if (ExternalAcct != "" && is_date(FirstCompDate) && is_date(LastCompDate) && CompCode != "")
                    {
                        // set up Oracle reader ---------------------
                        cnt += 1;
                        OraCmd.CommandText = "Insert into CIRC.TH_STC_Temp Values ("
                                           + cnt.ToString()
                                           + ", 0"
                                           + ", '" + CompCode
                                           + "', to_date('" + FirstCompDate + "','YYYYMMDD')"
                                           + ", to_date('" + LastCompDate + "','YYYYMMDD')"
                                           + ",'" + ExternalAcct
                                           + "', '" + row[5] 
                                           + "', '" + row[20] + "')";
                        OraCmd.ExecuteScalar();
                    }

Open in new window

0
Comment
Question by:mtnseeker
  • 2
2 Comments
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 2000 total points
ID: 35427557
Before adding your apostrophe's, use the escape.

..to escape a single quote, simply add another single quote.
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35427565
example...

Comments = row[20].Replace("'","''");
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 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